1.

Identify the output of the below java program and Justify your answer.

Answer»

class Main { public static void main(String args[]) { SCALER s = new Scaler(5); }}class InterviewBit{ InterviewBit(){ System.out.println(" Welcome to InterviewBit "); }}class Scaler extends InterviewBit{ Scaler(){ System.out.println(" Welcome to Scaler ACADEMY "); } Scaler(int X){ this(); super(); System.out.println(" Welcome to Scaler Academy 2"); }}

The above code will throw the compilation error. It is because the super() is used to call the parent class constructor. But there is the condition that super() must be the first statement in the block. Now in this case, if we replace this() with super() then also it will throw the compilation error. Because this() also has to be the first statement in the block. So in conclusion, we can say that we cannot USE this() and super() keywords in the same block.



Discussion

No Comment Found