Methods and Constructors

Quiz Guidelines

 

Multiple Choice Question

QID: 
302

Which of the following are true about the "default" constructor?

Select 2 options

A. It is provided by the compiler only if the class does not define any constructor. 
B. It initializes the instance members of the class. 
C. It calls the default 'no-args' constructor of the super class. 
D. It initializes instance as well as class fields of the class. 
E. It is provided by the compiler if the class does not define a 'no- args' constructor.

Multiple Choice Question

QID: 
301

What will the following program print?

public class TestClass{  
static int someInt = 10;  
public static void changeIt(int a){  
  a = 20;  }  
public static void main(String[] args){   
 changeIt(someInt);    
System.out.println(someInt);  } }

Select 1 option 

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

Descriptive Question

QID: 
300

Complete the code using blue labels on the right so that the ouput will 210.
(You may have some blanks empty.)

public int a= a+offset;
return a;
u.update(a,111);
a= u.update(a,111);
return;
public void
public class Updater

{

                                       update(int a, int offset)

{

                                     

                                     

}

public static void main(String [] args)

{

Updater u= new Updater();

int a = 99;
                                     

System.out.println(a);

}

}

Multiple Choice Question

QID: 
299

Consider the following class definition:

public class TestClass{
public static void main(){ new TestClass().sayHello(); } //1
public static void sayHello(){ System.out.println("Static Hello World"); public void sayHello() { System.out.println("Hello World "); } //3
}

What will be the result of compiling and running the class?

Select 1 option

A. It will print Hello World.
B. It will print Static Hello World.
C. Compilation error at line 2.
D. Compilation error at line 3.
E. Runtime Error.

Multiple Choice Question

QID: 
298

What will be the output when the following program is run?

public class TestClass{
char c;
public void m1(){
char[ ] cA = { 'a' , 'b'};
m2(c, cA);
System.out.println( ( (int)c) + ", " + cA[1] );
}
public void m2(char c, char[ ] cA){
c = 'b';
cA[1] = cA[0] = 'm';
}
public static void main(String args[]){
new TestClass().m1();
}
}

Select 1 option

A. Compile time error.
B. , m
C. 0 , m
D. b , b
E. b , m

Pages