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 ) ; } }02.0Compile time error None of the above
Question
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 ) ; } }02.0Compile time error None of the above
Solution
The output of the program will be 2.0.
Here's the step by step explanation:
-
The program defines a class named
Numwith a constructor that takes a double as an argument. This constructor prints out the value of the argument. -
The
Testclass extends theNumclass. -
In the
mainmethod of theTestclass, an instance of theNumclass is created with the argument 2. -
This calls the constructor of the
Numclass, which prints out the value 2.0 (since it's a double).
So, the output of the program is 2.0.
Similar Questions
What is the output of the following code?public class Solution { public void display() { int x = 10; } public static void main(String args[]) { System.out.println(x); }}Options: Pick one correct answer from below100Compile time errorRuntime error
What is the output of the following code?public class Solution { public static void main(String args[]) { double x = 79.85; System.out.println(Math.round(x)); } } Options: Pick one correct answer from below798079.8None of the above
Select the correct answerWhat will be the output of the following Java program?class Output { public static void main(String args[]) { double ct1 = 3.0; double ct2 = 2.0; double ct3 = Math.pow( ct1, ct2 ); System.out.print(ct3); } }Options3.02.09.08.0
What is the output of the following code?public class Test { int x = 10; public static void main(String args[]) { System.out.print(x); } static { System.out.println(x + 10); }}Options: Pick one correct answer from below10 20errorexceptionNone of the above
What is the output of the following code snippet?class MyClass { static int count = 0; public MyClass() { count++; } public static int getCount() { return count; }}public class Main { public static void main(String[] args) { MyClass obj1 = new MyClass(); MyClass obj2 = new MyClass(); System.out.println(MyClass.getCount()); }}Question 3Answera.0b.1c.2d.Compilation error
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.