Object---The Ultimate Superhero??

Discussion in 'Java' started by Tango Issac Debian, Jul 15, 2006.

  1. Tango Issac Debian

    Tango Issac Debian New Member

    Joined:
    May 3, 2006
    Messages:
    31
    Likes Received:
    1
    Trophy Points:
    0
    Java, has become now undoubtedly the fuel of the development of the Software System Technology.Developers, now thus take the challenge to prove the feelings of Java as the best positive catalyst of their development life's reactions.They feel the Class, as the ultimate classic sense of the Java.Class,makes the expansibility of the Java's Application totally outstanding.But, in the behind of the defining,using of the classes there is some interesting concepts are embedded .Actually, all the classes that we define are subclasses by default--if you like it or not ! Because, it is the truth that all the classes have a standard class,"Object", as a root or base.So, "Object" is saying as the SUPERCLASS of every of our classes. But, the most interesting matter is to specify that the class "Object" ,need not necessary to specify in the definition of our own classes ----It here generates automatically.


    There are some interesting consequences of having "Object" as a universal superclass.One of that, a variable of type Object can store a reference to an object of any class type.This is useful when we want to write method that needs to handle objects of unknown type.We can also define a parameter to the method of type, Object , in which case a reference to any type of object can be passed to the method.It gives us the flexibility to include code in the method whenever we want.

    Ofcourse, our classes will inherit the members from the class Object. These all happen to be methods of which Seven are public and two are protected.

    The seven public methods are:

    1)tostring():

    The methods return the String object that describes the current object.

    2)equals() :

    This compares the reference to the object passed as an argument with the reference to the current object and returns true if they are equals.

    3)getclass():

    This method returns an object of type Class that identifies the class of current object.

    4)hashcode():

    This method calculates a hashcode value of an object and returns it as type int.

    5)notify():

    This is used to wake up a thread associated with the current object.

    6)notifyAll():

    This is used to wake up all threads associated with the current object.

    7)wait():

    This method causes a thread to wait for a change in the current object.


    Note that getClass(),notifyAll(),notify() and wait() cannot be overwridden in our classs definitions---they are fixed with the keyword "final"in their definition .

    The two protected methods are-------

    1)clone():

    This will create an object that is a cppy of the current object regardless of type.

    2)finalize() :

    This is the method that is called to cleanup when an object is destroyed.


    Thus, it is the actual sence of the Object class in Java.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice