Advertisements
Advertisements
प्रश्न
Answer the following in brief. Give a program code example wherever applicable.
What is a parameterised constructor?
कोड लेखन
लघु उत्तरीय
Advertisements
उत्तर
A parameterised constructor is a constructor that accepts one or more parameters to initialise the object with specific values.
class Student
{
int id;
Student(int x) {
id = x;
}
public static void main(String[] args)
{
Student s = new Student(101);
System.out.println(s.id);
}
}
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 4: Constructors - Exercises [पृष्ठ ११५]
