1)If we do not provide any constructor then default constructor will be added implicitly by the compiler to that class. 2)Now what I mean by default constructor is : Your class: class A {}
This is what compiler generates for you:
class A extends java.lang.Object { A() { super(); // call to Object class constructor. } }
3)You can check this using javap JVM command. class A { } >javac A.java >javap A class A extends java.lang.Object{ A(); }
4)If you extend some class other than java.lang.Object
Your code:class A {} class B extends A {}
And this is what compiler generates for you:
class A extends java.lang.Object { super(); // call constructor of Object class.Impilcit }
class B extends A { // Now it doesn't extend Object class
Hai, Thank you for the response. But my doubt is ,How can we acces the Object class methods wothout creating an instance for the Object class. For example: we can apply equals() method without creating an instance for the Object Class. How is it possible,to access the method of Object class without any instance??? Hope it is clear now.
I think its because its[object class]is something that u get in the java.lang package which we all get by default and can use stuff like the System class or use any java keyword for that matter.
Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.
That is a IS-A relationship.
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
Gift giving made easy with the permaculture playing cards