English

Consider the given program and answer the questions given below: class temp { int a; temp() { a=10 } temp(int z) a=z; } void print() { System.out.println(a); } void main() { temp t = - Computer Applications

Advertisements
Advertisements

Question

Consider the given program and answer the questions given below:

class temp
      {
      int a;
      temp()
      {
      a=10
      }
      temp(int z)
      a=z;
      }
      void print()
      {
      System.out.println(a);
      }
      void main()
      {
      temp t = new temp();
      temp x = new temp(30);
      t.print();
      x.print();
      }
      }
  
  1. What concept of OOPs is depicted in the above program with two constructors?
  2. What is the output of the method main()?
Short/Brief Note
Advertisements

Solution

  1. Polymorphism. Having two constructors in a class represents constructor overloading, which is a part of polymorphism.
  2. 10
    30
shaalaa.com
Principles of Object Oriented Programming (OOP)
  Is there an error in this question or solution?
2023-2024 (March) Official
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×