123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Education >> View Article

Object Class Supermost Class In Java Inherited By All Classes

Profile Picture
By Author: Infocampus
Total Articles: 33
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

Object class in java is the super most class in java.Every class in java directly or indirectly inherit the Object class.

The Object class is the parent class of all the classes in java by default. In other words, it is the topmost class of java.
The Object class is beneficial if you want to refer any object whose type you don't know. Notice that parent class reference variable can refer the child class object, know as upcasting.
Object class is present in java.lang package. Every class in Java is directly or indirectly derived from the Object class.java course in bangalore
If a Class does not inherit any other class then it is direct child class of Object class and if inherits other class then it is an indirectly derived. Therefore the Object class methods are available to all Java classes. Hence Object class acts as a root of inheritance hierarchy in any Java Program.
Methods Of Object class:
toString() : toString() provides String representation of an Object and used to convert an object to String .toSting() is overrided by the String class.
Whenever we try to print any Object reference, ...
... then internally toString() method is called.
Example :
Employee e = new Employee();

// Below two statements are equivalent
System.out.println(e);
System.out.println(e.toString());
java training center bangalore
hashCode(): For every object, JVM generates a unique number which is hashcode. It returns distinct integers for distinct objects.It convert the internal address of object to an integer by using an algorithm. Hash code is used to search object in a collection.

equals(Object obj): This method is mainly used to compare the address of the objects. If we compare the same object it returns true and if we are comparing the different object it returns false because two objects have different address.

When equals() is override by String class then it compare the content of the object.

Integer obj1 = new Integer(2),
Integer obj2= new Integer(4);

if (obj1.equals(obj2))
System.out.println("objects are equal");
else
System.out.println("objects are not equal");
Output : objects are not equal
best core java training in bangalore
Explanation : In above obj1 and obj2 is the reference variable of two different object. Both objects are having different address so while comparing it returns false.

getClass():
This method returns the runtime class of this Object.getClass()
The getclass method is a final method (cannot be overridden) that returns a runtime representation of the class of this object. This method returns a Class object.

We can use the class Object for a variety of information about the class, such as its name, its superclass, and the names of the interfaces that it implements. The following method gets and displays the class name of an object:
Advance java training in bangalore

void displayClassName(Object obj)
{
System.out.println("The Object's class is " + obj.getClass().getName());
}

finalize() : This method is called just before an object is garbage collected. It is called by theGarbage Collector on an object when garbage collector determines that there are no more references to the object.

clone(): It returns a new object that is exactly the same as this object.It is used to get the copy of the object.

Notify() :This method wakes up a single thread that is waiting on object's monitor.

NotifyAll(): This method wakes up all threads that are waiting on object's monitor.

Java/j2ee classes bangalore

Wait() : This method causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for object.

This is the brief description about the Object class ,to learn more about the java join Infocampus Software Training Institute.

Author :Infocampus provides java course in bangalore with the live project. Attend 4 days free demo classes for java training. Training is given by experienced trainers.Syllabus is according to getting the job easily.
Infocampus provides best core java training in bangalore with the 100% placement assistance.Learn Core & Advance Java in the easiest way.
To get the free demo classes on java/j2ee classes Contact at : 9738001024 or for more details on Advance java training
or visit at: http://www.infocampus.co.in/java-training-bangalore.html

Total Views: 632Word Count: 661See All articles From Author

Add Comment

Education Articles

1. Data Science Institutes In Hyderabad | Ai Course Online
Author: Hari

2. Top Sap Ariba Training In Hyderabad | Online And Ameerpet Classes
Author: krishna

3. Why University Of Hertfordshire Is Top Study Abroad College?
Author: Ritik Kumar

4. Oic Training In Hyderabad | Oic Online Training
Author: naveen

5. Ai Agents Training In India | Ai Agents Course Online
Author: gollakalyan

6. Launch Your Career: How A 3-month Course In Digital Marketing Can Transform Your Future
Author: Shivam Kumar

7. Why An Emba Is A Game-changer For Small Business Owners ?
Author: IIBMS Institute

8. Your Proqual Level 7 Nvq Diploma Questions, Answered
Author: Gulf Academy of Safety

9. How To Reduce School Fees: Smart Ways To Manage Education Costs
Author: Shiksha Academy

10. Your Ultimate Guide To Mbbs In Philippines
Author: Mbbs Blog

11. Necessary Information About Mbbs In Mauritius!
Author: Mbbs Blog

12. Mbbs In Egypt For Indian Students: Affordable, Recognized, And English-medium Education
Author: Mbbs Blog

13. Pursue Mbbs In Bangladesh: Quality Education With Affordability For Indian Students
Author: Mbbs Blog

14. How To Calculate The Return On Investment (roi) Of A Marketing Campaign
Author: madhuri

15. Master Safety Compliance: A Manager's Guide To The Nebosh Igc
Author: Gulf Academy Safety

Login To Account
Login Email:
Password:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: