Wednesday 19 August 2015

Java Tutorial : Inheritance Example Child Parent


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
Child.java
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();

    }
}
Output
Property of Child
Property of Parent
Child method
Parent method
To Download InheritanceDemoChildParent Project Click the below link
https://sites.google.com/site/javaee4321/java/InheritanceDemoChildParent.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment