Inheritance in Object-Oriented Programming
What is a hash code?
An integer representation of an object's memory location.
There is no such concept as hash code.
A boolean value that represents whether an object is unique in the program or not.
A string representation of an object that usually contains its properties.
Which of these best describes what happens when you call equals() on two different objects with identical data if their class doesn't override equals() from Object?
It returns false because Object's default implementation compares memory locations.
It returns true because it checks equality based on similar data within objects.
It throws a runtime exception as equals() needs to be overridden to compare objects properly.
It compiles but does nothing since equals() must be specifically invoked with matching data types.
What is the primary benefit of overriding a method from the Object superclass in a custom class?
It guarantees that no other methods can be added to the custom class, maintaining simplicity.
It causes runtime errors if the overridden method does not behave exactly like its original version in Object.
It allows customization of the method's behavior to fit the specific needs of the custom class.
It prevents other classes from using or extending this method, ensuring exclusivity.
What potential issue arises when implementing cloneable interface's clone method via calling super.clone on an object containing deep references without further action?
Implementing Clonable mandates explicit ClassNotFoundException handle make sure cloning well-defined.
Shallow cloning leads copies sharing deep reference leading possible unintended side-effects shared state manipulation.
Deep copied references unreachable cloned object, triggering garbage collector prematurely collecting resources still use.
The clone returns null pointer exception dereferencing deep copy hasn't properly initialized post-cloning.
Which option correctly states what occurs when .clone() is called on an object whose class implements Cloneable but doesn't override clone()?
The program will compile successfully but throw a CloneNotSupportedException at runtime.
Nothing happens because clone must be overridden explicitly in order for copying functionality to work; otherwise, it simply won't execute anything at all during runtime operations/execution flow.
The protected clone method from Object is used resulting in a shallow copy of fields if accessible by caller code via reflection or inside package scope classes/methods due to its protected
access modifier in Object
.
A deep copy of that object including all nested referenced objects gets created automatically without any issues or exceptions thrown at runtime due to 'clone()' being public in 'Object'.
When using polymorphism, what would be expected if method equals() is not overridden and two distinct objects with identical states are compared using .equals()?
The objects will be considered unequal because they are different instances.
A compiler error occurs as .equals() must be overridden when using polymorphism.
The runtime system throws an exception due to ambiguous comparison logic.
The objects will be considered equal because they have identical states.
Which statement best describes what happens when an exception is thrown but not caught within a method?
The Java Virtual Machine (JVM) immediately terminates all threads and halts execution.
The method retries execution from the point where the exception occurred until it succeeds.
The exception must be declared in a throws clause, or it will result in a compilation error.
The exception propagates up to the calling method in the call stack.

How are we doing?
Give us your feedback and let us know how we can improve
In Java why would one use 'instanceof' when dealing with objects derived from different hierarchy levels?
This obligates immediate conversion casting between unrelated types/classes circumventing potential issues related incompatible assignments ..
It exclusively constrains objects restrictively binding them tightly together hindering loose decoupling flexible interactions amongst variously ranked relatives..
It verifies if an instance belongs down certain hierarchies/lineages thus enabling type-safe casting/checking across varied related entities.
It applies polimorphism forcing every descendant entity adhere strictly identical contracts/signatures regardless rank/hierachy position..
Which method of the Object class is used to compare two objects for equality?
compare()
compareTo()
isEqual()
equals()
Which method is automatically called when an object is passed to System.out.println()?
toString()
getString()
printObject()
display()