Methods and Constructors

Quiz Guidelines

 

Multiple Choice Question

QID: 
297

Consider the following method:

public void myMethod(int m, Object p, double d)
{  ... valid code here }

Assuming that there is no other method with the same name, which of the following options are correct regarding the above method?

Select 1 option
 A. If this method is called with two parameters, the value of d in the method will be 0.0. 
B. If this method is called with one parameter, the value of p and d in the method will be null and 0.0 respectively. 
C. If this method is called with one parameter, the call will throw a NullPointerException. 
D. If this method is called with one parameter, the call will throw a NullPointerException only if the code in the method tries to access p. 
E. If this method is called with two parameters, the code will not compile. 

Multiple Choice Question

QID: 
296

Which of the following methods does not return any value?

Select 1 option 

A. public doStuff() throws FileNotFoundException, IllegalArgumentException{    //valid code not shown } 
B. public null doStuff() throws FileNotFoundException, IllegalArgumentException{    //valid code not shown } 
C. public doStuff() {    //valid code not shown } 
D. public void doStuff() throws FileNotFoundException, IllegalArgumentException{    //valid code not shown } 
E. private doStuff() {    //valid code not shown } 

Multiple Choice Question

QID: 
295

What will be the result of attempting to compile and run the following class?

public class InitTest{
static String s1 = sM1("a");{
s1 = sM1("b");
}
static{
s1 = sM1("c");
}
public static void main(String args[]){
InitTest it = new InitTest();
}private static String sM1(String s){
System.out.println(s); return s;
}   }

Select 1 option

A. The program will fail to compile.
B. The program will compile without error and will print a, c and b in that order when run.
C. The program will compile without error and will print a, b and c in that order when run.
D. The program will compile without error and will print c, a and b in that order when run.
E. The program will compile without error and will print b, c and a in that order when run.

Multiple Choice Question

QID: 
294

What will the following program print when compiled and run:

public class TestClass {
public static void main(String[] args) {
someMethod();
}
static void someMethod(Object parameter) {
System.out.println("Value is "+parameter);
}
}

Select 1 option

A. It will not compile.
B. Value is null
C. Value is
D. It will throw a NullPointerException at run time.

Multiple Choice Question

QID: 
293

What will the following program print when run?

public class ChangeTest {
private int myValue = 0;
public void showOne(int myValue){
myValue = myValue;
System.out.println(this.myValue);
}public void showTwo(int myValue){
this.myValue = myValue;
System.out.println(this.myValue);
}public static void main(String[] args) {
ChangeTest ct = new ChangeTest();
ct.showOne(100);
ct.showTwo(200);
}
}

Select 1 option

A. 0 followed by 100.
B. 100 followed by 100.
C. 0 followed by 200.
D. 100 followed by 200.

Pages