Select chapter



basics (7.papers)
constructors (1.papers)
packages (1.papers)
inheritance (7.papers)
misc (3.papers)
exceptions (5.papers)
threads (4.papers)
overloading (1.papers)
jsp (3.papers)
servlets (9.papers)
jdbc (2.papers)
util (1.papers)
xml (2.papers)
IO stream (3.papers)
Hide

Sponsored Links


  

java interview questions and answers

Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
6
What will be the result of compiling and running the given program? 

1. interface I1 {}  
2. class A {}  
3. class Q extends A implements I1  
4. {  
5. public static void main(String[] args) 
6. { 
7. A a =null;  
8. I1 i1 = (I1)a;  
9. } 
11.}
  1. Program compiles and run without any error.
  2. Program compiles correctly but give NullPointerException when executed.
  3. Compile time error at line number 7
  4. Compile time error at line number 8
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
9
class OuterTest{ 
  class InnerTest{}
}
public class Tester{
  OuterTest.InnerTest i= XXX; 
}

Which of the following when replaced in place of XXX will compile?
  1. OuterTest().new InnerTest()
  2.  new OuterTest().new InnerTest()
  3.  new InnerTest();
  4.  new OuterTest.InnerTest();
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
11
package a;
public  class OuterClass{ 
 public class InnerClass{ 
 }
} 

Which  is the right way to create InnerClass in another class in package b?
  1. new a.OuterClass().InnerClass()
    
  2. new a.OuterClass.InnerClass() 
    
  3. new a.OuterClass().a.InnerClass()
    
  4. new a.OuterClass().new InnerClass()
Show Answer
Share Facebook gmail Twitter
12
interface A{ 
 void m(); 
}
abstract public class Tester implements A{  
 void m(int i){} 
}

Which of the following is true?
  1. code does not compile because m() method in Tester class does not match with m() method of interface A
  2. code does not compile because Tester class does not implement m()
     
  3. Code does not compile because m() method in Tester class must be declared public
  4. Code compiles
Show Answer
Share Facebook gmail Twitter
13
Given the following, 

interface A{ 
 int x=10; 
 void f(); 
}
 
Which of the given options are valid definition?
  1. interface B implements A {  }
  2. abstract class B extends A {public  void f(){}}
  3. abstract class B implements A {public  void f(){}}
  4.  class B implements A {public  void f(){x=20;}}
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
15
Which of the following  is a recommended way to make constants available globally in a Java application?
  1.  declare static final constants outside any class
  2.  declare static final constants in a separate header file and include this file in all the java classes
  3. declare constants  in an interface and  import this interface in all the java files
  4. declare constants  in an abstract class and import this class in all the java files
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
17
interface A { 
 int i=9; 
 void show(); 
} 
class B implements A{
}
  1. Will compile if class B is declared abstract
  2. Will compile if class B is declared final
  3. Will compile successfully
  4. None of the Above
Show Answer
Share Facebook gmail Twitter
18
Which of the following statement(s) is false about an anonymous inner class?
  1. It does not have a constructor.
  2. It can implement an interface.
  3. It can implement an interface and extend a non-final class (at the same time).
  4.  It can extend a non-final Class.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Read more papers :