Sunday, April 27, 2014

How can a class extends another class, extends Object? Is it not multiple inheritance which is not allowed in Java?


Let me explain

We know every class in java extends Object class.Lets say if you have a class Employee

public class Employee{  
 private String name;  
 // getters and setters  
 }  

Then this class implicitly like this

public class Employee extends Object{  
 private String name;  
 // getters and setters  
 }  


But if your class extends another class explicitly then 

 public class Employee extends BaseEmployee{  
 private String name;  
 // getters and setters  
 }  

Then your Employee class doesn't extends Objects class.Instead your BaseEmployee will extends Object class.

Hope you get it ;)

No comments:

Post a Comment