Submitted by c-admin on Wed, 05/29/2019 - 03:51
Given the following definitions and reference declarations:
interface I1 { }
interface I2 { }
class C1 implements I1 { }
class C2 implements I2 { }
class C3 extends C1 implements I2 { }
C1 o1;
C2 o2;
C3 o3;
Which of these statements are legal?
Select 3 options
A. class C4 extends C3 implements I1, I2 { }
B. o3 = o1;
C. o3 = o2;
D. I1 i1 = o3; I2 i2 = (I2) i1;
E. I1 b = o3;
Submitted by c-admin on Wed, 05/29/2019 - 03:46
Consider the following code:
interface Flyer{ String getName(); }
class Bird implements Flyer{
public String name;
public Bird(String name){
this.name = name;
}public String getName(){ return name; }
}
class Eagle extends Bird {
public Eagle(String name){
super(name);
}
}public class TestClass {
public static void main(String[] args) throws Exception {
Flyer f = new Eagle("American Bald Eagle"); //PRINT NAME HERE
} }
Which of the following lines of code will print the name of the Eagle object?
Select 3 options
A. System.out.println(f.name);
B. System.out.println(f.getName());
C. System.out.println(((Eagle)f).name);
D. System.out.println(((Bird)f).getName());
E. System.out.println(Eagle.name);
F. System.out.println(Eagle.getName(f));
Submitted by c-admin on Wed, 05/29/2019 - 03:42
Consider the following classes :
interface I{
}
class A implements I{
}
class B extends A {
}
class C extends B{
}
And the following declarations:
A a = new A();
B b = new B();
Identify options that will compile and run without error.
Select 1 option
A. a = (B)(I)b;
B. b = (B)(I) a;
C. a = (I) b;
D. I i = (C) a;
Submitted by c-admin on Wed, 05/29/2019 - 03:39
Given the following class definitions :
interface MyIface{};
class A {};
class B extends A implements MyIface{};
class C implements MyIface{};
and the following object instantiations:
A a = new A();
B b = new B();
C c = new C();
Which of the following assignments are legal at compile time?
Select 1 option
A. b = c;
B. c = b;
C. MyIface i = c;
D. c = (C) b;
E. b = a;
Submitted by c-admin on Wed, 05/29/2019 - 03:32
What will the following code print when run?
class Baap {
public int h = 4;
public int getH() {
System.out.println("Baap " + h);
return h;
}
} public class Beta extends Baap {
public int h = 44;
public int getH() {
System.out.println("Beta " + h);
return h;
} public static void main(String[] args) {
Baap b = new Beta();
System.out.println(b.h + " " + b.getH());
Beta bb = (Beta) b;
System.out.println(bb.h + " " + bb.getH());
}
}
Select 1 option
A. Beta 44
4 44
Baap 44
44 44
B. Baap 44
4 44
Beta 44
44 44
C. Beta 44
4 44
Beta 44
4 44
D. Beta 44
4 44
Beta 44
44 44
Pages