Hai ra

core java interview questions and answers | core java interview questions and answers for freshers | core java interview questions and answers for experienced

core java interview questions and answers | core java interview questions and answers for freshers | core java interview questions and answers for experienced

Hi today iam sharing more core java interview question after wards i will share advanced java interview questions and answers.

core java interview questions and answers

 

1. What are the instance variables?
Instance variables are those which are defined at  class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values.
2. How to define a constant variable in the Java?
The variable should be declared as static and final. So only one copy of  variable exists for all instances of the class and the value can't be changed also.

3. Should a main() method be compulsorily declared in all java classes YEs or NO?
No not required The main() method should be defined only if the source class is  java application.
4. What is  return type of the main() method?
Main() method doesn't return anything hence it is as declared void.
5. Why is  main() method declared static?
main() method is called by  JVM even before the instantiation of the class hence it is declared as static.
6. What is  arguement of main() method?
main() method accepts an array of String object as arguement.

7. Can a main() method be overloaded?
Yes. You can have any number of main() methods with different method signature and implementation in the class.
8. Can a main() method be declared final Yes or No?
Yes. Any inheriting class will not be able to have it's own default main() method.
9. Does the order of public and static declaration matter in the  main() method?
No. It doesn't matter but, the void should always come before main().
10. Can a source file contain more than one class declaration Yes or No?
Yes a single source file can contain any number of Class declarations but only one of  class can be declared as public.
11. What is a package?
Package is a collection of related classes and interfaces. package declaration should be the first statement in a java class.
12. Which package is imported by as default?
java.lang package is imported by default even without a package declaration.

 

 


Previous
Next Post »