Methods and Constructors

Quiz Guidelines

 

Multiple Choice Question

QID: 
109

Which of the following are valid declarations?

Select 1 option

A. abstract int absMethod(int param) throws Exception;
B. abstract native int absMethod(int param) throws Exception;
C. float native getVariance() throws Exception;
D. abstract private int absMethod(int param) throws Exception;
E. strictfp float f;

Multiple Choice Question

QID: 
108

What will the following program print when run?

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

Select 1 option

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

Multiple Choice Question

QID: 
107

How can you declare a method someMethod() such that an instance of the class is not needed to access it and all the members of the same package have access to it?

Select 3 options

A. public static void someMethod()
B. static void someMethod()
C. protected static void someMethod()
D. void someMethod()
E. protected void someMethod()
F. public abstract static void someMethod()

Multiple Choice Question

QID: 
106

What will the following program print when run?

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

Select 1 option

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

Multiple Choice Question

QID: 
105

Which of the following correctly defines a method named stringProcessor that can be called by other programmers as follows: stringProcessor(str1) or stringProcessor(str1, str2) or stringProcessor(str1, str2, str3),
where str1, str2, and str3 are references to Strings.

Select 1 option

A. public void stringProcessor(...String){
}
B. public void stringProcessor(String... strs){
}
C. public void stringProcessor(String[] strs){
}
D. public void stringProcessor(String a, String b, String c){
}
E. Three separate methods need to be written.

Pages