Submitted by c-admin on Tue, 05/28/2019 - 01:35
What will be the result of attempting to compile and run the following program?
public class TestClass{
public static void main(String args[ ] ){
Object a, b, c ;
a = new String("A");
b = new String("B");
c = a;
a = b;
System.out.println(""+c);
}
}
Select 1 option
A. The program will print java.lang.String@XXX, where XXX is the memory location of the object a.
B. The program will print A
C. The program will print B
D. The program will not compile as a,b and c are of type Object.
E. The program will print java.lang.String@XXX, where XXX is the hash code of the object a.
Submitted by c-admin on Tue, 05/28/2019 - 01:31
What will be the contents of s1 and s2 at the time of the println statement in the main method of the following program?
import java.util.*;
public class TestClass{
public static void main(String args[]){
Stack s1 = new Stack ();
Stack s2 = new Stack ();
processStacks (s1,s2);
System.out.println (s1 + " "+ s2);
}
public static void processStacks(Stack x1, Stack x2){
x1.push (new Integer ("100")); //assume that the method push adds the x2 = x1;
}
}
Select 1 option
A. [100] [100]
B. [100] []
C. [] [100]
D. [] []
Submitted by c-admin on Tue, 05/28/2019 - 01:25
What will the following code print when compiled and run:
class Data {
int intVal = 0;
String strVal = "default";
public Data(int k){
this.intVal = k;
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
Data d1 = new Data(10);
d1.strVal = "D1";
Data d2 = d1;
d2.intVal = 20;
System.out.println("d2 val = "+d2.strVal);
}
}
Select 1 option
A. d2 val =
B. d2 val = default
C. d2 val = D1
D. Exception at run time.
Submitted by c-admin on Tue, 05/28/2019 - 01:22
Given:
class StaticTest{
void m1(){
StaticTest.m2(); // 1
m4(); // 2
StaticTest.m3(); // 3
}
static void m2(){ } // 4
void m3(){
m1(); // 5
m2(); // 6
StaticTest.m1(); // 7
}
static void m4(){ }
}
Which of the lines will fail to compile?
Select 2 options
A. 1
B. 2
C. 3
D. 4
E. 5
F. 6
G. 7
Submitted by c-admin on Tue, 05/28/2019 - 01:18
Identify valid method declarations.
Select 1 option
A. public void methodX(int... i, String s);
B. public void methodX(int... i, String... s);
C. public void methodX(int i, int... j);
D. public int... methodX(int i);
Pages