Created
December 2, 2019 06:37
-
-
Save AnujJha-stack/29bb8ee8cf018fd3fac181b8887e8aa2 to your computer and use it in GitHub Desktop.
Inheritance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Main{ | |
public static void main(String[] a){ | |
Student s1 = new Student(); | |
s1.setRollNumber(1); | |
s1.setName("Anuj"); | |
s1.setAge(21); | |
System.out.println("RollNUmber: "+s1.getRollNumber()+"\tName : "+s1.getName()+"\tAge : "+s1.getAge()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person{ | |
private int age; | |
private String name; | |
public void setName(String name){ | |
this.name = name; | |
} | |
public void setAge(int age){ | |
this.age = age; | |
} | |
public int getAge(){ | |
return(age); | |
} | |
public String getName(){ | |
return(name); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student extends Person{ | |
private int rollNumber; | |
public void setRollNumber(int rollNumber){ | |
this.rollNumber = rollNumber; | |
} | |
public int getRollNumber(){ | |
return(rollNumber); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment