Tuesday, 5 January 2016

Java Tutorial : Java initialize using final method


Click here to watch in Youtube :
https://www.youtube.com/watch?v=Oq1rAsgBr68&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java initialize using final method
Parent.java
public class Parent
{

    public int capacity = initializeInstanceVariable(10);

    protected final int initializeInstanceVariable(int value)
    {

        System.out.println("Inside final method.");

        capacity = value;
        return capacity;
    }

}
Child.java
public class Child extends Parent
{

    public static void main(String args[])
    {

        Child child = new Child();

        System.out.println("capacity : " + child.capacity);

        /*
         * Subclass reusing the initialization method.
         */
        child.initializeInstanceVariable(200);

        System.out.println("capacity : " + child.capacity);

    }
}
Output
Inside final method.
capacity : 10
Inside final method.
capacity : 200
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/InstanceMemberInitializeDemo-Final-App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/InstanceMemberInitializeDemo-Final-App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/41d9dfe14fcf9b8b617da7211fce54dcabe49f5c/BasicJava/InstanceMemberInitializeDemo-Final-App/?at=master

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