Can an object be garbage collected while it is still reachable

A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected. No, an object cannot be garbage collected while it is still reachable. In Java, the garbage collector is responsible for reclaiming memory occupied by objects that are no longer reachable or referenced by any live part of the program. If an … Read more

Which class is extended by all other classes

The Object class is extended by all other classes. In Java, the Object class is the root class for all other classes. Every class in Java is either directly or indirectly derived from the Object class. Therefore, the correct answer to the question “Which class is extended by all other classes?” is the Object class.

What is the difference between a Window and a Frame

The Frame class extends Window to define a main application window that can have a menu bar. In the context of Core Java, specifically in the context of GUI (Graphical User Interface) programming using Swing, a Window and a Frame refer to different classes provided by the Java Foundation Classes (JFC) library. Frame: A Frame is a top-level container … Read more

When can an object reference be cast to an interface reference

An object reference be cast to an interface reference when the object implements the referenced interface. In Java, an object reference can be cast to an interface reference when the object’s class implements that interface. This is possible because Java supports polymorphism through interfaces. Here’s a brief explanation: When the Object Implements the Interface: If … Read more

What is the % operator

It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand. In Core Java, the % operator is the modulus operator. It is used to find the remainder when one number is divided by another. Here’s an example: java int a = 10; … Read more