Q42
What is the output of the above program? class Num Num(double x ) System.out.println( x ) ; public class Test extends Num public static void main(String[] args) Num num = new Num( 2 ) ;
A.
0
B.
2.0
C.
Compile time error
AnswerD.
None of the above
Answer: Option C
Solution
Answer: Option C
Solution:
The given program creates a class Num that has a constructor with a double parameter.In the main method, an object of the Num class is created with the value 2, which is passed as a double value.
Since 2 is treated as an integer, Java automatically converts it to a double (2.0), and the constructor prints this value.
Thus, the output of the program is 2.0.