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