When is an Object Subject to Garbage Collection

An object is subject to garbage collection when it becomes unreachable to the program in which it is used. In Java, an object becomes eligible for garbage collection when there are no more references to it. The Java Virtual Machine (JVM) has a garbage collector that automatically identifies and removes objects that are no longer … Read more

Can an Unreachable Object Become Reachable Again

An unreachable object may become reachable again. This can happen when the object’s finalize() method is invoked and the object performs an operation which causes it to become accessible to reachable objects. No, in Java, once an object becomes unreachable, it cannot become reachable again. An object becomes unreachable when there are no references to it from … Read more

How Does a Try Statement Determine Which Catch Clause Should be Used to Handle an Exception

When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exception is executed. The remaining catch clauses are ignored. In Java, when an exception is thrown within a try block, the Java runtime system looks … Read more

What Are The Object And Class Classes Used For

The Object class is the highest-level class in the Java class hierarchy. The Class class is used to represent the classes and interfaces that are loaded by a Java program. In Core Java, the Object and Class classes serve distinct purposes. Object Class: The Object class is at the top of the Java class hierarchy. Every class in Java … Read more

What Modifiers May be Used with a Top-Level Class

A top-level class may be public, abstract, or final. In Java, a top-level class can have the following modifiers: public: The class is accessible to any other class. (no modifier): If no modifier is specified, the class is only accessible within the same package. This is sometimes referred to as having package-private access. It’s important to note that … Read more