DEV Community

Sathish K
Sathish K

Posted on

Test Question

Different between static and non static variable.
Static variable:
It is can be accessed using the class.
It is the accessed by the static and non static methods.
It is a reduce the amount of the memory used by the program.
It is a existing the entire lifetime of the program.
It is default value is can assigned automatically.

Non static variables:
It is can be accessed using the instance of the class.
It is cannot be accessed by the inside the static variables.
It is not reduce the amount of the memory used by the program.
It is the existing the lifetime of the program.
It's a default value is cannot assigned automatically.

Different between the local and global variables.

Local variable:
Local variable are declared within the block of the code,such as method or function and have limited scope and lifetime. The code is execution only within the block.

Global Variable:
Global variables are declared the program within the outside of the any function and can be accessed from any part of the program, persisting throughout is execution.

Different between the method and constructor.
Method:
A method must have a return type.
A method is a collection of the statement which return a value upon its execution.
A method cannot create object run to with automatically.
Same method name with different parameters
A method is consisted of java code to the executed.
Constructor:
A constructor doesn't have a return type.
A constructor is a block of code that can initialize a newly object to create.
A constructor can be create a object is run to with automatically.
Same Constructor name with different parameter list.
A constructor can be used to initialize an object.

Top comments (0)