Wednesday, July 29, 2015

questionare 1

1. Object creation in java utilizes the keyword.
a. new
b. Car()
c. SampleProgram
d. class


2. Which of the following shows the syntax for the object creation for a defined object?
a. < object reference name > = new <arguments>(<class name>);
b. <class name> = new <object name>(<arguments>);
c. <object reference name> = <class name> <identifier>;
d. < object reference name > = new <class name>(<arguments>);

3) When a constructor is called ?
a) At the time calling method
b) At the time of creating object
c) At the time of main method call by JVM
d) None of these


4) Predict the output of following code fragment
class ConTest {
    private ConTest() {
    System.out.println(" impossible ");
        }
    public static void main(String[] arg) {
    ConTest ct = new ConTest();
        }
}


a) Prints "impossible"
b) Compilation fails because constructor scope is private
c) Thows exception at runtime
d) Print "impossible" and throws exception


5) class Con {
    private Con() {
    System.out.println(" it is very simple ");
   }
class ConDemo {


    public static void main(String[] arg) {
    Con c = new Con();
        }
}


a) Compilation fails
b) Runtime error
c) Prints " it is very simple"
d) None of these option


6) "this" keyword refers to ______________
a) current object
b) sub-class object
c) super-class object
d) all objects at a time

7) this  keyword is used to call ___


a) Constructor of class in which this keyword is used
b) Constructors of super class
c) Constructors of sub class
d) Constructors of all classes


8) Predict the output of the following code
class Demo {
    int i;
    Demo(int i){
        i = i;
    }
    void show(){   
        System.out.println(i);
    }
    public static void main(String[] arg) {
        Demo d = new Demo(10);
        d.show();
    }
}
  
a) 0
b) 10
c) Compilation fails
d) Runtime error


9) Predict the output of the following code


class Demo {
    int i;
    Demo(int i){
        this.i = i;
    }
    void show(){   
        System.out.println(i);
    }
    public static void main(String[] arg) {
        Demo d = new Demo(10);
        d.show();
    }
}


a) 10
b) 0
c) Compilation fails
d) Runtime error

10) class Sample {
public static void main(String[] args) {
// create object here
 }
}
Which statement creates object of Sample class ?
a) Sample  s  =  new Sample();
b) Sample  s  =  new  Sample;
c) Sample  s;
d) Sample  new =  s  Sample();


11) this keyword can appear anywhere inside constructor block
?  (True/False)?
12) Constructor never return a value. Even then, Constructor can have return statement with no return value
?  (True/False)?
13) Constructor returns a value
?  (True/False)?
14) Constructor name should be as same as name of class which it is contained in
?  (True/False)?
15) A class can have more than one constructor? (True/False)?



No comments:

Post a Comment