Core Java - Interview Questions and Answers


  1. Can a class declared as private be accessed outside it's package?
    Not possible.
  2. Can a class be declared as protected?
    The protected access modifier cannot be applied to class and interfaces. Methods, fields can be declared protected, however methods and fields in a interface cannot be declared protected.
  3. What is the access scope of a protected method?
    A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package.
  4. What is the purpose of declaring a variable as final?
    A final variable's value can't be changed. final variables should be initialized before using them.
  5. What is the impact of declaring a method as final?
    A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation.
  6. I don't want my class to be inherited by any other class. What should i do?
    You should declared your class as final. But you can't define your class as final, if it is an abstract class. A class declared as final can't be extended by any other class.

« Prev   [ Page 5 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 |