Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sampath Kumar S Assistant Professor, SECE

Similar presentations


Presentation on theme: "Sampath Kumar S Assistant Professor, SECE"— Presentation transcript:

1 Sampath Kumar S Assistant Professor, SECE
Object class Sampath Kumar S Assistant Professor, SECE

2 1/10/2019 Object class in Java The Object class is the parent class of all the classes in java by default. If no inheritance is specified for the classes then all those classes are subclass of the object class. In other words, it is the superclass of all the other classes by default. Example: public class A {…..} Is equal to public class A extends Object {….} Sampath Kumar S, AP

3 Methods of Object class
1/10/2019 Methods of Object class Method Description public final ClassgetClass() Returns the Class class object of this object. The Class class can further be used to get the metadata of this class. public int hashCode() Returns the hashcode number for this object. public boolean equals(Object obj) Compares the given object to this object. protected Object clone() throws CloneNotSupportedException Creates and returns the exact copy (clone) of this object. public String toString() Returns the string representation of this object. public final void notify() Wakes up single thread, waiting on this object's monitor. Sampath Kumar S, AP

4 Cont.., Method Description public final void notifyAll()
1/10/2019 Cont.., Method Description public final void notifyAll() Wakes up all the threads, waiting on this object's monitor. public final void wait(long timeout)throws InterruptedException Causes the current thread to wait for the specified milliseconds, until another thread notifies (invokes notify() or notifyAll() method). public final void wait(long timeout,int nanos)throws InterruptedException Causes the current thread to wait for the specified milliseconds and nanoseconds, until another thread notifies (invokes notify() or notifyAll() method). public final void wait()throws InterruptedException Causes the current thread to wait, until another thread notifies (invokes notify() or notifyAll() method). protected void finalize()throws Throwable Is invoked by the garbage collector before object is being garbage collected. Sampath Kumar S, AP

5 1/10/2019 toString() The toString method Returns the string representation of the object. Syntax: public String toString() if it is invoked this will return a string which describes the object. The return string consist of and objects memory address in hexadecimal form. Sampath Kumar S, AP

6 1/10/2019 Example: toString(); import java.io.*; class A extends Object { } class B extends A public class Test { public static void main(String args[]) { A str = new A(); System.out.println("Return Value: "+str); System.out.println("str.toString()“ +str.toString()); } Output: Return Value: Sampath Kumar S, AP

7 Example: toString() - Overridding
1/10/2019 Example: toString() - Overridding import java.io.*; class A extends Object { public String toString()// Method overridden { String Str = "Hi IT"; return Str; } } class B extends A { } public class Test { public static void main(String args[]) { A str = new A(); System.out.println("Return Value: "+str); System.out.println("str.toString()“ +str.toString()); Output: Return Value: Hi IT str.toString() Hi IT Sampath Kumar S, AP

8 1/10/2019 Sampath Kumar S, AP

9 1/10/2019 Thank we  Sampath Kumar S, AP


Download ppt "Sampath Kumar S Assistant Professor, SECE"

Similar presentations


Ads by Google