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

1
Which one will not be inherited into derived class? constructors or nested classes?
  1. derived class will inherit the properties and behaviors from base class depending on the access modifiers.
  2. nested classes of base class will be inherited into derived class based on the access modifier rules.
  3. Constructors of base class will be inherited into derived class, if they are not private.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
3
What is not possible in Inheritance?
  1. you can access default, protected, public variable of base class, in derived class if derived class is also in same package.
  2. you can declare same variable name in derived class as in base class. Thus hiding it.
  3. you can access default, protected, public variable of base class, in derived class if derived class is in different package.
  4. all are possible.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
7
When a derived class object is created, which constructor will be executed first, base class constructor or derived class constructor?
  1. base class constructor will be executed first and then derived class constructor.
  2. derived class constructor will be executed first and then base class constructor.
  3. both base and derived class constructors will be executed simultaneously.
  4. we can't predict in which order constructors are going to execute.
Show Answer
Share Facebook gmail Twitter
8
Why base class constructors are executed first? and then derived?
  1. I don't know, java document says so, that's why.
  2. It is a standard.
  3. May be we will be using some of the base class variables in derived class constructor.
  4. none
Show Answer
Share Facebook gmail Twitter
9
If a class don't inherit any other class, still does it have any base class?
  1. In that case no.
  2. If you don't inherit any thing, java compiler will automatically extends your class with Object class.
  3. If you don't inherit any thing, java compiler will automatically extends your class with Class class.
  4. none
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
11
In below program, where all java compiler will add super() call.
class Base{
        public Base(){
                System.out.println("base constructor");
        }
}
class Der extends Base{
        public Der(){
                System.out.println("derived constructor");
        }
}
public class InheritanceDemo {
        public static void main(String[] args) {
                Der d = new Der();
        }
}
  1. java compiler adds super() call as the first line in the Der() constructor before system.out.printlin("derived constructor");
  2. java compiler adds super() call as the first line in the Base() constructor before system.out.printlin("base constructor");
  3. both option 1 and 2 are correct
  4. both option 1 and 2 are correct, but it is not mandatory that it will add super() call as the first line.
Show Answer
Share Facebook gmail Twitter
12
Which of the below statements are false about calling a constructor?
  1. you can call one constructor from other constructor of same class.
  2. you can call constructor of base class from the derived class.
  3. you can call constructor of one class from an instance method of same class by using this()
  4. you can't have iterative constructor calls, which compiler will catch at compiling time itself.
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
17
Which of the below is not a function of Object class.
  1. hashCode
  2. equals
  3. equalsIgnoreCase
  4. clone
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
20
What is hashCode, in java?
  1. hashcode is the hexadecimal address of the object created in the heap.
  2. no two objects created using new keyword will have same hashcodes.
  3. hashcode will not be displayed when you apply toString() on some object.
  4. if two objects are having same hashcode that means, both are pointing to same object in the heap.
Show Answer
Share Facebook gmail Twitter
Read more papers :