Last active
December 8, 2020 05:04
-
-
Save ucguy4u/2f025f7f4c6663b5033b11a93f296654 to your computer and use it in GitHub Desktop.
eg: Inheritance in Java
This file contains 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 Teacher { | |
String designation = "Teacher"; | |
String collegeName = "CMU"; | |
void does() { | |
System.out.println("teaching"); | |
} | |
} | |
public class MathsTeacher extends Teacher { | |
String mainSubject = "Maths"; | |
public static void main(String[] arg) { | |
MathsTeacher mt = new MathsTeacher(); | |
System.out.println(mt.collegeName); | |
System.out.println(mt.designation); | |
System.out.println(mt.mainSubject); | |
mt.does(); | |
} | |
} | |
/** | |
* OUTPUT: | |
* CMU | |
* Teacher | |
* Maths | |
* teaching | |
* <p> | |
* Based on the example, the MathsTeacher class is a child class of Teacher. | |
* The child class MathsTeacher forms a IS-A relationship with the parent class Teacher. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment