Thursday, June 7, 2018

Technical Tip #17 - Technical Tip of the day...


T17: Knowledge Tip Of The Day.....
Why Object is Super Class in Java?
java.lang.Object class is the super base class of all Java classes. Every other Java classes descends from Object.
It is not a explicit requirement forced on the developer. If a class is declared without extending another class then it will implicitly extend Object class. This is taken care of by the JVM. This is not applicable for the interfaces. A Java interface does not extends the Object.
Following could be the reasons for this design decision, :
By having the Object as the super class of all Java classes, without knowing the type we can pass around objects using the Object declaration.
Before generics was introduced, imagine the state of heterogeneous Java collections. A collection class like ArrayList allows to store any type of classes. It was made possible only by Object class hierarchy.
The other reason would be to bring a common blueprint for all classes and have some list of functions same among them. I am referring to methods like hashCode(), clone(), toString() and methods for threading which is defined in Object class.
Super class of String, Object, Class --
public class SuperClass {
public static void main(String args[]) {
String str = new String("Hi");
Class strClass = str.getClass();
System.out.println("Super class of String: " + strClass.getSuperclass());
Object obj = new Object();
Class objClass = obj.getClass();
System.out.println("Super class of Object: " + objClass.getSuperclass());
Class classClass = objClass.getClass();
System.out.println("Super class of Class: "
+ classClass.getSuperclass());
}
}


Regards,

javabykiranhr1@gmail.com
#Java #Learn #Upgrade #Training #Classes #OnlineLecture #OnlineVideos #Pune
Follow On LinkedIn @ https://bit.ly/2J2MbvU   
Join Our Google Group @ https://bit.ly/2sjbIuq  
#Call Now to book your seat to JOIN Java Training @ 7219474925, eMail @ javabykiranhr1@gmail.com
#Visit us @ www.JavaByKiran.com
#Java #J2EE
#Core +#Advance + #Struts +#Hibernate + #Spring + #REST + #OCJP + #OCWCD + #Maven + #Junit + #Jquery #Ajax + #XML
#Spring Boot + CI and many more ..
#Selenium
#Complete #Java + #Selenium + #TestNg + #Jenkin + #Webdriver + #Cucumber +#Maven + #DataProvider + #Keyword + #Hybrid + #POM End to End integration #Jenkin #Maven #Testng and many more ..
#JavabyKiran #Expert #Training #BestInstitute #Java #Python #Selenium #Freshers #Professionals #IT #Software #Career #Interview #Jobs#Jobopening  #BestTrainingInstituteinPune #ITCourses  #OnlineVideo  #Pune

No comments:

Post a Comment