Interview Questions - Core Java
13.
What are instance variables?
Instance variables are those which are defined at the class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values.
14.
How to define a constant variable in Java?
The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed also.
static final int MAX_LENGTH = 50; is an example for constant.
static final int MAX_LENGTH = 50; is an example for constant.
15.
Should a main() method be compulsorily declared in all java classes?
No not required. main() method should be defined only if the source class is a java application.
16.
What is the return type of the main() method?
Main() method doesn't return anything hence declared void.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers