Is it possible to inherent some of the property from the parent class to child class in java.
In one of my situation i have to take only 3 properties from the parent while my parent has 100 property.
If yes then what is the way.?
Thanks in advance.
Is it possible to inherent some of the property from the parent class to child class in java.
In one of my situation i have to take only 3 properties from the parent while my parent has 100 property.
If yes then what is the way.?
Thanks in advance.
 
    
    I recommend you either refactor your code, or simply don't use the 97 properties you don't need.
Your super-class shouldn't be more complex than your subclass. The purpose of your subclass should be to implement or add functionality. Inserting a lot of properties that you won't use defeats the point of inheritance and class hierarchies.
Perhaps you can divide the many properties of your super-class and instead put them in sub-classes.
 
    
    Yes, We can do it. Just Extend the parent class
 class Teacher {
       String designation = "Teacher";
       String collegeName = "Beginnersbook";
       void does(){
        System.out.println("Teaching");
       }
    }
public class PhysicsTeacher extends Teacher{
   String mainSubject = "Physics";
   public static void main(String args[]){
    PhysicsTeacher obj = new PhysicsTeacher();
    System.out.println(obj.collegeName);
    System.out.println(obj.designation);
    System.out.println(obj.mainSubject);
    obj.does();
   }
}
Java Inheritance you can check out this link to learn more.
