Click here to watch in Youtube :
https://www.youtube.com/watch?v=CNi365Zhqso&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Inheritance Example Child Parent |
class Parent { String parentProperty = "Property of Parent"; public void parentMethod() { System.out.println("Parent method"); } } public class Child extends Parent { String childProperty = "Property of Child"; public void childMethod() { System.out.println("Child method"); } public static void main(String[] args) { Child childObject = new Child(); /* * Using child Object we can access child properties and parent * properties because Child class extends Parent Class. */ System.out.println(childObject.childProperty); System.out.println(childObject.parentProperty); /* * Using child Object we can access child methods and parent methods * because Child class extends Parent Class. */ childObject.childMethod(); childObject.parentMethod(); } }
Property of Child Property of Parent Child method Parent method
https://sites.google.com/site/javaee4321/java/InheritanceDemoChildParent.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment