Thursday, October 11, 2012

How to call default Constructor from a Parametarized Constructor in Java

Code Snap for above Issue is...............
 

public class Test {
int i;
 Test(){
  System.out.println("hariom");
 }
 public Test(int i){
  this();
  this.i = i;
  System.out.println("Hariom23"+i);
 }
  
 
 public static void main(String a[]){
  Test test = new Test(8);
 }
}

And the Output will be ....
hariom
Hariom238

No comments:

Post a Comment