Wednesday, April 3, 2019

Java Interview Questions Part-3

1. What is object class in java ?
Answer :- Object class is a Superclass in java. by default all Java classes inherit from java.lang.Object. The Object class, in the java.lang package.

2. What is the difference between equals () and == in Java?
Answer:- 

if we compare two object references to check equality.
Using "==" : its returns true only if both references points to same object.
Using  equals() : it return true or false based on the implementation of overridden equals() methods in class.

3. What is hashCode() and equals() methods contact in java ?

4. What are the methods of object class in java ?

Object Class Methods :

                                        Methods                                               Description
 public final Class getClass()  Class class is used to get the class from instance.
 public int hashCode()  Used to get the hascode of an object.
 public boolean equals(Object obj)  Used to check equality of two object. It should be override in class.
 by default equals() method of java.lang.Object compares memory   addresses,
 that means all objects are different from each other
 (only two references to the same object will return true).
 protected Object clone() throws   CloneNotSupportedException  To get clone of an object. By default its return shallow copy but   maintain encapsulation.
 public String toString()
 public final void notify()  notify() method is used to wakes up single thread, waiting on this   object's monitor.
 public final void notifyAll()  notifyAll() method is used to wakes up all the threads, waiting on this   object's monitor.
 public final void wait(long timeout)throws   InterruptedException  This will wait for notify until given specified milliseconds.
 public final void wait(long timeout,int   nanos)throws  InterruptedException
 public final void wait()throws InterruptedException
 protected void finalize()throws Throwable  This method is used to clean up operations on an object before it is     removed from the memory.
 Finalize() method is called before Garbage Collector call on jvm.





Related Tutorials

No comments:

Post a Comment