Constructor in Java Example – Java Constructor Example Program

By | December 17, 2010
Constructor in Java Example - Java Constructor Example Program. You can find Source code (code snippets) for Constructor in Java.

Constructor in Java Example – Java Constructor Example Program. You can find Source code (code snippets) for Constructor in Java.

class Test{

int studentId;

public Test(int studentId){

this.studentId=studentId;

}

public int getId(){

return studentId;

}

}

public class Constructor{

public static void main(String args[]){

Test t=new Test(50);

System.out.println(t.studentId);

System.out.println(t.getId());

}

}

Result:

50

50

Leave a Reply

Your email address will not be published. Required fields are marked *