Set 26

Multiple Choice Question

QID: 
217

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;

Multiple Choice Question

QID: 
216

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

Multiple Choice Question

QID: 
215

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;

Multiple Choice Question

QID: 
214

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;

Multiple Choice Question

QID: 
213

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

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) Arrays (1) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (55) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exception (1) Exceptions (4) Exercise (1) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (5) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (9) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (11) Java Programmer 2 (7) Javascript Frameworks (1) Java SE Professional (1) JPA 1 - Module (6) JPA 1 - Modules (1) JSP (1) Legacy Java (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quartz Scheduler (1) Quizzes (17) RabbitMQ (1) references (2) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Site Usage Guidelines (1) Sorting (1) source code management (1) spring (4) spring boot (3) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) troubleshooting (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)