You are on page 1of 10

 A constructor

(a) Must have the same name as the class it is declared within.
(b) Is used to create objects.
(c) May be declared private
(d) Both (A) and (B) above
(e) (a), (b) and (c) above. 
 A constructor is invoked automatically (T/F)?
a) TRUE 
b) FALSE
 The numeric data members are bydefault initialized as
a) Garbage
b) 0 
c) TRUE
d) null
 Variables declared as default can be accessible
a) Only in the class
b) Within a package 
c) Within a subclass
d) Outside of a package
 Private members of a class are accessible in another class
directly (T/F)
a) TRUE
b) FALSE 
 What is true about constructor?
a) It can contain return type
b) It can take any number of parameters 
c) It can have any non access modifiers
d) Constructor cannot throw an exception
What is the output of the following

class T {
  int t = 20;
}
1. 0
class Main {
2. 20 
   public static void main(String args[]) {
3. Compiler error
      T t1 = new T();
4. Runtime error
      System.out.println(t1.t);
   }
}
 ‘This’ keyword is used to differentiate instance variables and
local variable having the same name(T/F)
a) TRUE 
b) FALSE
 is the return type of a method can be used to distinguish
overloaded methods(T/F)
a) TRUE
b) FALSE 
Which of the following is True?

Which of the following is/are true about


constructors in Java?

1) Constructor name should be same as 1. 1


class name.
2. 1,2
2) If you don't define a constructor for a
class, a default parameterless constructor 3. 1,2,3
is automatically created by the compiler.
3) The default constructor calls super() and 4. 1,2,3,4 
initializes all instance variables to default
value like 0, null.
4) If we want to parent class constructor, it
must be called in first line of constructor.

You might also like