Submitted by c-admin on Tue, 06/04/2019 - 23:05
Consider the following code:
public class TestClass {
//define tester method here
public static void main(String[] args) throws Exception {
TestClass tc = new TestClass();
while(tc.tester()){
System.out.println("running...");
}
}
}
Which of the following options would be a valid implementation of tester() method?
Select 2 options
A. public boolean tester(){
return false;
}
B. public Boolean tester(){
return false;
}
C. public tester(){
return false;
}
D. public int tester(){
return 0;
}
E. public String tester(){
return "false";
}
Submitted by c-admin on Tue, 06/04/2019 - 22:59
Consider the following method:
static int mx(int s){
for(int i=0; i<3; i++){
s = s + i;
}
return s;
}
and the following code snippet:
int s = 5;
s += s + mx(s) + ++s;
System.out.println(s);
What will it print?
Select 1 option
A. 21
B. 22
C. 23
D. 24
E. 25
F. 26
Submitted by c-admin on Tue, 06/04/2019 - 22:56
What will be the result of attempting to compile and run the following code?
class SwitchTest{
public static void main(String args[]){
for ( int i = 0 ; i < 3 ; i++){
boolean flag = false;
switch (i){
flag = true;
}
if ( flag ) System.out.println( i );
}
}
}
Select 1 option
A. It will print 0, 1 and 2.
B. It will not print anything.
C. Compilation error.
D. Runtime error.
E. None of the above.
Submitted by c-admin on Tue, 06/04/2019 - 22:54
Consider the following class:
public class ArgsPrinter{
public static void main(String args){
for(int i=0; i<3; i++){
System.out.print(args+" ");
}
}
}
What will be printed when the above class is run using the following command line: java ArgsPrinter 1 2 3 4
Select 1 option
A. 1 2 3
B. ArgsPrinter 1 2
C. java ArgsPrinter 1 2
D. 1 1 1
E. None of these.
Submitted by c-admin on Tue, 06/04/2019 - 22:51
Note: This question may be considered too advanced for this exam. What will the code shown below print when compiled and run with the following command line?
java WarZone self interface XMen {
void shoot(String a);
}public class WarZone {
public static void main(String[] args){
XMen x = null;
if(args.length() > 0){
x = new XMen(){
public void shoot(String s){
for(int i=0; i<s.length; i++){
System.out.println("shot : "+s.charAt(i));
}
}
};
}if(x != null){
x.shoot(args[0]);
}
}}
Select 1 option
A. It will not compile because interface XMen cannot be instantiated.
B. It will print shot : 4 times, one at each line.
C. It will print "shot : s", "shot : e", "shot : l", "shot : f" one by one on 4 lines.
D. It will compile but will throw an exception at runtime.
E. None of these options is correct.
Pages