Thursday, 8 October 2015

"This" keyword usage in Java


public class Acceptt {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Third obj = new Third(10,20);
  obj.show();
  }

}



class Second {

 void show(){
 
  System.out.println("I am Parent");
 }

}


class Third extends Second{
 int i,j;

 void show(){

  System.out.println("I am child");
 }
 Third(){
  System.out.println("Third constructor");
 }

 Third(int i,int j){
  this();
  this.i=i;
  this.j=j;
  System.out.println("The values are "+i  +j);
  }

 void display(){
  this.show();
 }

}


output:-
Third constructor
The values are 1020
I am child

No comments:

Post a Comment