हिंदी

Answer the following in brief. Give a program code example wherever applicable. What is a parameterised constructor?

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 [पृष्ठ ११५]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 4 Constructors
Exercises | Q 3. (iii) | पृष्ठ ११५
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×