A class contains constructors that are invoked to create objects from the class blueprint. Constructor declarations look like method declarations—except that they use the name of the class and have no return type.
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());
}
}
Constructor JAVA
Reviewed by Abdul hanan
on
09:58:00
Rating:
Constructor in java
ReplyDeletegood tips