Set 24

Multiple Choice Question

QID: 
377

Consider the following classes in one file named A.java...

abstract class A{   
protected int m1(){ return 0; } } 
class B extends A{   int m1(){ 
return 1; } }

Which of the following statements are correct...

Select 1 option 

A. The code will not compile as you cannot have more than 1 class in 1 file. 
B. The code will not compile because class B does not override the method m1() correctly. 
C. The code will not compile as A is an abstract class. 
D. The code will not compile as A does not have any abstract method. 
E. The code will compile fine. 

Multiple Choice Question

QID: 
376

Note: This question may be considered too advanced for this exam. Given:

class MySuper{
public MySuper(int i){ }
}
abstract class MySub extends MySuper{
public MySub(int i){ super(i); }
public abstract void m1();
}
class MyTest{
public static void main(String[] args){
MySub ms = new MySub(){
public void m1() { System.out.println("In MySub.m1()"); }
};
ms.m1();
}
}

What will be the output when the above code is compiled and run?

Select 1 option

A. It will not compile.
B. It will throw an exception at run time.
C. It will print In MySub.m1()
D. It will compile and run without any exception but will not print anything.

Multiple Choice Question

QID: 
375

Which of these statements concerning interfaces are true?

Select 2 options

A. An interface may extend an interface.
B. An interface may extend a class and may implement an interface.
C. A class can implement an interface and extend a class.
D. A class can extend an interface and can implement a class.
E. An interface can only be implemented and cannot be extended.

Multiple Choice Question

QID: 
374

Given the following source code, which of the lines that are commented out may be reinserted without introducing errors?

abstract class Bang{
 //abstract void f();  //(0)
   final    void g(){}
 //final    void h(){} //(1)
   protected static int i;
   private int j;
}
final class BigBang extends Bang{
 //BigBang(int n) { m = n; } //(2)
   public static void main(String args[]){
      Bang mc = new BigBang();
   }
   void h(){}
 //void k(){ i++; } //(3)
 //void l(){ j++; } //(4)
   int m;
}

Select 1 option

A. final void h( ) { } //(1)
B. BigBang(int n) { m = n; }  //(2)
C. void k( ) { i++ }   //(3)
D. void l( ) { j++ }  //(4)
E. abstract void f( ) ;  //(0)

Multiple Choice Question

QID: 
373

You are modeling a class hierarchy for living things. You have a class LivingThing which has an abstract method reproduce().
Now, you want to have 2 subclasses of LivingThing - Plant and Animal. Both do reproduce but the mechanisms are different. What would you do?

Select 1 option

A. Overload the reproduce method in Plant and Animal classes
B. Overload the reproduce method in LivingThing class.
C. Override the reproduce method in Plant and Animal classes
D. Either overload or override reproduce in Plant and Animal classes, it depends on the preference of the designer.

Pages

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) ArrayLists (1) Arrays (2) 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) (52) 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 (4) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (7) 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 (8) Javascript Frameworks (1) Java SE Professional (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) resources (1) 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)