Knowee
Questions
Features
Study Tools

Analyze the following code and choose a correct answer from below. public class Test {    public static void main(String[] args) {     B b = new B();     b.m(5);     System.out.println("i is " + b.i);   } } class A {   int i;   public void m(int i) {      this.i = i;    } }  class B extends A {   public void m(String s) {   } } Group of answer choicesThe program has a compile error, because m is overridden with a different signature in B.The program has a compile error, because b.m(5) cannot be invoked since the method m(int) is hidden in B.The program has a runtime error on b.i, because i is not accessible from b.The method m is not overridden in B. B inherits the method m from A and defines an overloaded method m in B.

Question

Analyze the following code and choose a correct answer from below. public class Test {    public static void main(String[] args) {     B b = new B();     b.m(5);     System.out.println("i is " + b.i);   } } class A {   int i;   public void m(int i) {      this.i = i;    } }  class B extends A {   public void m(String s) {   } } Group of answer choicesThe program has a compile error, because m is overridden with a different signature in B.The program has a compile error, because b.m(5) cannot be invoked since the method m(int) is hidden in B.The program has a runtime error on b.i, because i is not accessible from b.The method m is not overridden in B. B inherits the method m from A and defines an overloaded method m in B.

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

Solution

The method m is not overridden in B. B inherits the method m from A and defines an overloaded method m in B.

Similar Questions

Analyze the following code. Please select all that apply.  public class Test {   public static void main(String[] args) {     Object a1 = new A();     Object a2 = new Object();     System.out.println(a1);     System.out.println(a2);   } } class A {   int x;   @Override   public String toString() {     return "A's x is " + x;   } } Group of answer choicesThe program cannot be compiled, because System.out.println(a1) is wrong and it should be replaced by System.out.println(a1.toString());When executing System.out.println(a1), the toString() method in the Object class is invoked.When executing System.out.println(a2), the toString() method in the Object class is invoked.When executing System.out.println(a1), the toString() method in the A class is invoked.

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

Analyze the following code. Please select all that apply. public class A extends B { } class B {   public B(String s) {   } } Group of answer choicesThe program has a compile error because A does not have a default constructor.The program has a compile error because the default constructor of A invokes the default constructor of B, but B does not have a default constructor.The program would compile fine if you add the following constructor into A: A(String s) { }The program would compile fine if you add the following constructor into A: A(String s) { super(s); }

Analyze the following code. Please select all that apply from the options below.  public class Test {   public static void main(String[] args) {     A a = new A();     a.print();   } }  class A {   String s;    A(String s) {     this.s = s;   }    void print() {     System.out.println(s);   } } Group of answer choicesThe program has a compile error because class A is not a public class.The program has a compile error because class A does not have a default constructor.The program compiles and runs fine and prints nothing.The program would compile and run if you change A a = new A() to A a = new A("5")

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

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.