Saturday, April 27, 2019

what is the output of the code?

Problem statement:
Given the code for constructor overloading. What will be the output?
  1. public class ConstructorCall {
  2.     ConstructorCall() {
  3.         System.out.println("default constructor");
  4.     }
  5.     ConstructorCall(int a){
  6.         this();
  7.         System.out.println("parameterized constructor");
  8.         System.out.println(10);
  9.     }
  10.     public static void main(String[] args) {
  11.         ConstructorCall st = new ConstructorCall(3);
  12.     }
  13. }
Output:
default constructor
parameterized constructor
10

No comments:

Post a Comment

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...