Java Interview Questions and Answers
Question - 61 : - What is a static method?
Answer - 61 : - A static method is a method that belongs to the class rather than any object of the class and doesn't apply to an object or even require that any objects of the class have been instantiated.
Question - 62 : - What is a protected method?
Answer - 62 : - A protected method is a method that can be accessed by any method in its package and inherited by any subclass of its class.
Question - 63 : - What is the difference between a static and a non-static inner class?
Answer - 63 : - A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.
Question - 64 : - What is an object's lock and which object's have locks?
Answer - 64 : - An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock. All objects and classes have locks. A class's lock is acquired on the class's Class object.
Question - 65 : - When can an object reference be cast to an interface reference?
Answer - 65 : - An object reference can be cast to an interface reference when the object implements the referenced interface.
Question - 66 : - What is the difference between a Window and a Frame?
Answer - 66 : - The Frame class extends Window to define a main application window that can have a menu bar.
Question - 67 : - What is the difference between a Window and a Frame?
Answer - 67 : - Heavy weight components like Abstract Window Toolkit (AWT), depend on the local windowing toolkit. For example, java.awt.Button is a heavy weight component, when it is running on the Java platform for Unix platform, it maps to a real Motif button. In this relationship, the Motif button is called the peer to the java.awt.Button. If you create two Buttons, two peers and hence two Motif Buttons are also created. The Java platform communicates with the Motif Buttons using the Java Native Interface. For each and every component added to the application, there is an additional overhead tied to the local windowing system, which is why these components are called heavy weight.
Question - 68 : - Which package has light weight components?
Answer - 68 : - javax.Swing package. All components in Swing, except JApplet, JDialog, JFrame and JWindow are lightweight components.
Question - 69 : - What are peerless components?
Answer - 69 : - The peerless components are called light weight components.
Question - 70 : - What is the difference between the Font and FontMetrics classes?
Answer - 70 : - The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object