हिंदी

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

प्रश्न

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()?
टिप्पणी लिखिए

उत्तर

  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)
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2023-2024 (February) Official
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×