B A class A { String name="A"; public String getName() { return name; } String greeting() { return "class A"; }}class B extends A { String name="B"; String greeting() { return "class B"; } }public class Test { public static void main(String arg[]) { A a=new A(); A b=new B(); System.out.println(a.greeting()+" has name "+a.getName()); System.out.println(b.greeting()+" has name "+b.getName()); }} Place the names "A" and "B" in the following output. class has name class has name
Question
B A class A { String name="A"; public String getName() { return name; } String greeting() { return "class A"; }}class B extends A { String name="B"; String greeting() { return "class B"; } }public class Test { public static void main(String arg[]) { A a=new A(); A b=new B(); System.out.println(a.greeting()+" has name "+a.getName()); System.out.println(b.greeting()+" has name "+b.getName()); }} Place the names "A" and "B" in the following output. class has name class has name
Solution
class A has name A class B has name A
Similar Questions
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; } }
class A {A(String s){System.out.println(s);}}class B {static A s1=new A("s11");static{ s1 = new A("s12");}}class C extends B {static{ s3 = new A("s31"); }static A s3=new A("s32");}// what's the output?C c = new C();
Analyze the following code carefully. Please select the one that applies.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); }}
class FourWheeler{ public FourWheeler() { System.out.println("Class FourWheeler"); }}class Car extends FourWheeler{ public Car() { System.out.println("Class Car"); }}class Audi extends Car{ public Audi() { super(); System.out.println("Class Audi"); }}class Driver{ public static void main(String args[]) { Audi cc=new Audi(); }}
what is the result of the following piece of code:public class Person{ public void talk(){ System.out.print("I am a Person"); }}public class Student extends Person{ public void talk(){ System.out.print("I am a Student"); }}public class Test{ public static void main(String args[]){ Person p = new Student(); p.talk(); }}I am a Person I am a Student I am a Person I am a StudentI am a Student I am a Person
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.