English

Explain the following term: Constructor overloading - Computer Applications

Advertisements
Advertisements

Questions

Explain the following term:

Constructor overloading

What is meant by constructor overloading? 

Explain the concept of constructor overloading with an example. 

Short Answer

Solution

  1. Constructor overloading refers to using multiple constructors with various argument lists under the same name. 
  2. Example:
    Cons()
    {
    }
    Cons(int x, int y)
    {
    }
    Cons(String s)
    {
    }
  3. The three constructors in the example share the same name, but differ in parameter types and number of values. Thus, they represent constructor overloading. The constructor invoked depends on the parameter list provided.
  4. Example: 
    Cons ob = new Cons("Hello World") // This will invoke the constructor, Cons(String s)
shaalaa.com
  Is there an error in this question or solution?
Chapter 7: Constructors - EXERCISES [Page 418]

APPEARS IN

Avichal Computer Applications [English] Class 10 ICSE
Chapter 7 Constructors
EXERCISES | Q V. 4. (d) | Page 418
Avichal Computer Applications [English] Class 10 ICSE
Chapter 7 Constructors
Review Insight | Q 2. | Page 415
Avichal Computer Applications [English] Class 10 ICSE
Chapter 7 Constructors
Review Insight | Q 6. | Page 415
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×