Knowee
Questions
Features
Study Tools

Select the correct answerPredict the correct results of below given code snippet: abstract class B { B() { System.out.println("38"); } void funTime() {   System.out.println("94"); } } class D extends B {  D() { System.out.println("103"); } } class Main { public static void main(String args[]) { D object = new D(); object.funTime(); } }Options10394381033894Error: Violating concept of abstract classes38103949410338

Question

Select the correct answerPredict the correct results of below given code snippet: abstract class B { B() { System.out.println("38"); } void funTime() {   System.out.println("94"); } } class D extends B {  D() { System.out.println("103"); } } class Main { public static void main(String args[]) { D object = new D(); object.funTime(); } }Options10394381033894Error: Violating concept of abstract classes38103949410338

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answer is "Error: Violating concept of abstract classes".

Explanation: In Java, an abstract class cannot be instantiated, which means you cannot create an object of an abstract class. The purpose of an abstract class is to function as a base for subclasses. The error occurs at the line "D object = new D();" because class B is abstract and cannot be instantiated. The constructor in the abstract class B will not be called and hence it will not print "38". The method funTime() in abstract class B will also not be called and hence it will not print "94". Therefore, the code will not execute and will throw an error.

This problem has been solved

Similar Questions

Select the correct answerDecode the code and choose the correct results: abstract class A { final void showTime() { System.out.println("3900"); } } class B extends A {   static void funTime() {     System.out.println("7766");   } } public class Main { public static void main(String args[]) { A object = new B(); object.showTime(); B.funTime(); } }Options7766390077667766Error3900390039007766

Select the correct answerPredict the correct results of below given code snippet: abstract class B { abstract void funTime(); } class D extends B { final void funTime() { System.out.println("47"); } } class Main { public static void main(String args[]) { B object = new D(); object.funTime(); } }OptionsClean code with 47 printed as output.Error : overriding method is finalCode gives warning due to use of final method , but also prints 47Code ex

Select the correct answerPredict the correct results of below given code snippet: abstract class CT {   public int x;   CT() {     x = 39;   }   abstract public void showTime();     abstract final public void funTime();  }  class Main extends CT {   public void showTime(int a) {     this.x = a;   }   final public void funTime() {     System.out.println(x);   }   public static void main(String[] args) {     Main object = new Main();     object.showTime(144);     object.funTime();   } }OptionsError3914439144

Select the correct answerWhat will be the output of the following Java program?class A { int i; void display() { System.out.println(i); }}class B extends A { int j; void display() { System.out.println(j); }}class inheritance_demo { public static void main(String args[]) { B obj = new B(); obj.i = 1; obj.j = 2; obj.display(); }}Options102Compilation Error

Analyze the following code and choose the correct answer from below.public class Test {   public static void main(String[] args) {     new B();   } } class A {   int i = 7;      public A() {     System.out.println("i from A is " + i);   }    public void setI(int i) {     this.i = 2 * i;   } } class B extends A {   public B() {     setI(20);     // System.out.println("i from B is " + i);       }    @Override   public void setI(int i) {     this.i = 3 * i;   } }

1/3

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.