Knowee
Questions
Features
Study Tools

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

Question

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

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

Solution

The correct answer is "39007766".

Here's the step by step explanation:

  1. An object of class A is created. However, since class A is abstract, it cannot be instantiated. So, it is instantiated as class B which is a subclass of A.

  2. The method showTime() is called on the object. Since this method is defined in class A and not overridden in class B, the method from class A is executed. This prints "3900".

  3. Then, the static method funTime() is called on class B. Static methods are called on the class itself, not on an instance of the class. This method prints "7766".

So, the output of the program is "39007766".

This problem has been solved

Similar Questions

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

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 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 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

Select the correct answerIf the code executes fine then predict the correct output otherwise choose the suitable option.class Code {    public void showTime() {       System.out.println("657");    }}  class Tantra extends Code {    public void showTime() {       System.out.println("-405");    }}  public class Main {    public static void main(String[] args) {        Code b = new Tantra();        b.showTime();    }}Options-405657error: showTime() in Tantra cannot override showTime() in Code657-405-405657

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.