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();
Question
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();
Solution
The output of the code will be:
s11 s12 s32 s31
Similar Questions
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); }}
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
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; } }
What will be the output of the following code?class A { void method() { System.out.println("Class A"); }}class B extends A { void method() { super.method(); System.out.println("Class B"); }}public class Main { public static void main(String[] args) { B obj = new B(); obj.method(); }}
Given:class FourWheeler { public FourWheeler () { System.out.print(1); } } class Car extends FourWheeler{ public Car() { System.out.print(2); } } class Audi extends Car{ public Audi() {System.out.print(3); } } public class Driver{ public static void main( String[] argv ) {new Audi(); } } What is the result when this code is executed?Select one:a.321b.The code runs with no outputc.123d.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.