Core Java Interview Questions Part II

What will be the value of Point p after methods in a and b if the value before method call is (700, 800)?
  1. static void changePoint ( Point p) {
        p.x = 100; p.y=200;

  2. static void changePoint(Point p) {
        p = new Point(100,200);

Answer :

  1. (100,200)

  2. (700,800)

[Note : Primitive type is passed by value in method parameter and objects are passed by value of the reference. In a method if the object values are changed , it will reflect, but if we try to change the reference itself its original reference/object will not change, as only copy of the reference is changed.]

Which one of these primitive types are unsigned?

  1. int

  2. long

  3. char

  4. double

  5. float

c) char (All numeric data types are signed. 'char' is the only unsigned integer type.)

Can inner class have static members?

No, inner class cannot have static members.

Can constructor throw exception?

Yes. [Constructor can throw exception.]

What is the rule regarding overriding methods throwing exceptions?

Overriding methods cannot throw more generic exceptions than base method.

Can finalize method be overloaded?

Yes, finalize method can be overloaded but only the below given version is called by garbage collector : protected void finalize() throws Throwable { };

Nested classes can extend only the enclosing class and cannot implement any interface. True/False?

False. [Nested class can extend any class or implement any interface.]

Can we declare derived class first and then base class in Java?

Yes, we can declare derived class first and then base class in Java.

GC is a high priority thread. True/False?

False. [GC is a low priority thread.]

Dictionary is an interface or a class?

Dictionary is a class and not an interface.

Member variables are resolved at compile time or runtime?

Member variables are resolved at compile time.

Map implements collection. True/False?

Map does not implement collection.

Random access file extends from File. True/False?

False [ Random access file descends from object and implements data input and data output.]

Can an interface be final?

No, interface cannot be declared final as they are implicitly abstract.

Can we have static method in interface?

All methods in an interface are implicitly public, abstract but never static.

Java supports both multi-dimensional and nested arrays. True/False?

False [Java does not support multi-dimensional arrays. It only supports nested arrays.]