Core Java - Interview Questions and Answers


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

« Prev   [ Page 4 of 22  Jump... Next »

Jump to page : 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |