orrect answerPredict the output of the given Java Program. class Circle { static String s = " "; protected Circle() { s += "Circle "; } } class SemiCircle extends Circle { private SemiCircle() { s += "Semi "; } } class SemisemiCircle extends Circle { private SemisemiCircle() { s += "SemiSemi "; } public static void main(String[] args) { new SemisemiCircle(); System.out.println(s); } }OptionsCircle SemiSemiSemiCircleSemi
Question
orrect answerPredict the output of the given Java Program. class Circle { static String s = " "; protected Circle() { s += "Circle "; } } class SemiCircle extends Circle { private SemiCircle() { s += "Semi "; } } class SemisemiCircle extends Circle { private SemisemiCircle() { s += "SemiSemi "; } public static void main(String[] args) { new SemisemiCircle(); System.out.println(s); } }OptionsCircle SemiSemiSemiCircleSemi
Solution
The output of the given Java program will be " Circle SemiSemi ".
Here's the step by step explanation:
-
When a new
SemisemiCircleobject is created in themainmethod, the constructor of its superclassCircleis called first. -
In the
Circleconstructor,
Similar Questions
What will be the output of the following code?public class Circle { private double radius; public Circle(double radius) { this.radius = radius; } public double getArea() { return Math.PI * radius * radius; } public static void main(String[] args) { Circle c = new Circle(2.5); System.out.println(c.getArea()); }}Question 14Answera.3.14b.6.28c.19.63d.Compilation error
A class Circle is defined in the following code:public class Circle { int radius; static String name; void getPerimeter() { } static void getArea() { }}Let c be an instance of Circle, which of the statements are correct?System.out.println(c.radius);c.getArea();c.getPerimeter();System.out.println(c.name);
Select the correct answerWhat is the output of the following Java program?public class Vehicle { public void move() { System.out.println("The vehicle moves"); }}public class Car extends Vehicle { public void move() { System.out.println("The car moves"); }}public class Main { public static void main(String[] args) { Vehicle vehicle = new Car(); vehicle.move(); }}Options"The car moves""The vehicle moves"The code does not compileNone of these
Select the correct answerPredict the output of the given Java Program. class Tiger { private final void flipper() { System.out.println("Tiger"); } } class Cub extends Tiger { public final void flipper() { System.out.println("Cub"); } public static void main(String[] args) { new Cub().flipper(); }}OptionsCubTigerCompilation FailsNone of the mentioned
What is the output of the given code?abstract class Shape{ int i = 111, j = 222; abstract void calcArea(); abstract void calcVolume();} abstract class Quadrilateral extends Shape{ void calcArea() { System.out.println(i); }}class Square extends Quadrilateral{ void calcVolume() { System.out.println(j); }}public class Test{ public static void main(String[] args) { Square c = new Square(); c.calcArea(); c.calcVolume(); }}Select one:a.Compile time error because 'class Square' is not override all the abstract methods, so should declare it as 'abstract'b.Compile time error because trying to instantiate the 'class Square' which does not override all the abstract methodsc.Run time Errord.111222
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.