Set 22

Multiple Choice Question

QID: 
490

What will be the output of the following program?

class CorbaComponent{
    String ior;
    CorbaComponent(){ startUp("IOR"); }
    void startUp(String s){ ior  =  s; }
    void print(){ System.out.println(ior); }
}
class OrderManager extends CorbaComponent{
   OrderManager(){  }
   void startUp(String s){  ior = getIORFromURL(s);   }
   String getIORFromURL(String s){  return "URL://"+s; }
}
public class Application{
   public static void main(String args[]){ start(new OrderManager()); }
   static void start(CorbaComponent cc){ cc.print(); }
}

Select 1 option

A. It will throw an exception at run time.
B. It will print IOR 
C. It will print URL://IOR 
D. It will not compile.
E. None of the above.

Multiple Choice Question

QID: 
489

What will the following program print when run?

class Super{
  public String toString(){
     return "4";
  }
}
public class SubClass extends Super{
  public String toString(){
     return super.toString()+"3";
  }
  public static void main(String[] args){
    System.out.println( new SubClass() );
  }
}

Select 1 option

A. 43
B. 7
C. It will not compile. 
D. It will throw an exception at runtime. 
E. None of the above.

Multiple Choice Question

QID: 
488

What will the following program print when run?

// Filename: TestClass.java

public class TestClass{
   public static void main(String args[] ){ A b = new B("good bye");  }
}
class  A{
   A() { this("hello", " world");  }
   A(String s) { System.out.println(s); }
   A(String s1, String s2){ this(s1 + s2); }
}
class B extends A{
   B(){ super("good bye"); };
   B(String s){ super(s, " world "); }
   B(String s1, String s2){ this(s1 + s2 + " ! "); }
}

Select 1 option

A. It will print "good bye". 
B. It will print "hello world". 
C. It will print "good bye world". 
D. It will print "good bye" followed by "hello world". 
E. It will print "hello world" followed by "good bye"

Multiple Choice Question

QID: 
487

Where, in a constructor, can you place a call to a super class's constructor?

Select 1 option

A. Anywhere in the constructor's body.
B. As the first statement in the constructor.
C. Only as the first statement and it can be called just like any other method call i.e. Class Name( ... ).
D. You can't call super class's constructor in a base class as constructors are not inherited..
E. None of the above.

Multiple Choice Question

QID: 
486

What would be the result of attempting to compile and run the following code?

// Filename: TestClass.java 

public class TestClass{   
public static void main(String args[]){      
B c = new C();      
System.out.println(c.max(10, 20));   } } 
class A{   int max(int x, int y)  { 
if (x>y) return x; 
else return y; } 
} 
class B extends A{  int max(int x, int y)  {  
return 2 * super.max(x, y) ; } 
} 
class C extends B{  int max(int x, int y)  {  
return super.max( 2*x, 2*y); } 
}

Select 1 option 

A. The code will fail to compile. 
B. Runtime error. 
C. The code will compile without errors and will print 80 when run. 
D. The code will compile without errors and will print 40 when run. 
E. The code will compile without errors and will print 20 when run.

Pages

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) (53) 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 (8) 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 (12) Java Programmer 2 (8) 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) 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)