मराठी

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×