Submitted by heartin on Sat, 08/22/2015 - 11:59
What will the following code print when run?
public class TestClass {
public void switchString(String input){
switch(input){
case "a" : System.out.println( "apple" );
case "b" : System.out.println( "banana" );
break;
case "B" : System.out.println( "Banana" );
default : System.out.println( "none" );
}
}
public static void main(String[] args) throws Exception {
TestClass tc = new TestClass();
tc.switchString("B");
}
}
Select 1 option
A. banana
Banana
B. Banana
none
C. Banana
D. banana
E. The code will not compile.
Submitted by heartin on Sat, 08/22/2015 - 07:55
What will the following program print?
class LoopTest{
public static void main(String args[]) {
int counter = 0;
outer:
for (int i = 0; i < 3; i++) {
middle:
for (int j = 0; j < 3; j++) {
inner:
for (int k = 0; k < 3; k++) {
if (k - j > 0) {
break middle;
}
counter++;
}
}
}
System.out.println(counter);
}
}
Select 1 option
A. 2
B. 3
C. 6
D.7
E. 9
Submitted by heartin on Wed, 08/19/2015 - 03:31
Given:
abstract class Abstract1 {
public abstract static void main(String[] args);
}
abstract class Concrete1 extends Abstract1{
public static void main(String[] args) {
System.out.println("I am an abstrsct class");
}
}
What will be the result is we compile and run Concrete1?
Select 1 option:
A. Class Abstract1 will not compile
B. Classes will compile, but will fail at runtime as Concrete1 is an abstract class
C. Class will compile, run and print "I am an abstract class"
D. Class will compile, run and print nothing
Submitted by jjadmin on Tue, 08/18/2015 - 12:43
Given:
abstract class Abstract1 {
public static void main(String[] args) {
System.out.println("I am an abstrsct class");
}
}
abstract class Concrete1 extends Abstract1{
}
What will be the result is we compile and run Concrete1?
Select 1 option:
A. Class Abstract1 will not compile as abstract classes cannot have main method
B. Classes will compile, but will fail at runtime as Concrete1 does not have a main method
C. Class will compile, run and print "I am an abstract class"
D. Class will compile, run and print nothing
Submitted by jjadmin on Tue, 08/18/2015 - 08:24
Given:
public abstract class Abstract1 {
public static void main(String[] args) {
System.out.println("I am an abstract class");
}
}
Select 1 option:
A. Class will not compile as abstract classes cannot have main method
B. Class will compile, but will not execute as we cannot execute an abstract class main method
C. Class will compile, run and print "I am an abstract class"
D. Class will compile, run and print nothing
Pages