Monday, 5 October 2015

Java parameterised constructor example

/**
 *
 */

/**
 * @author U0123154
 *
 */
public class ParamConstructor_24 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

ConstructorDemo i = new ConstructorDemo(10,20);

}

}



public class ConstructorDemo {
private int i;
private int k;
ConstructorDemo(int i,int k)
{
this.i=i;
this.k=k;
System.out.println("The \"i\" value is " +i);
System.out.println("The \"j\" value is " +k);
}
}

Output:-
The "i" value is 10
The "j" value is 20

No comments:

Post a Comment