JavaQuizzes

Quiz Guidelines

 

Multiple Choice Question

QID: 
1

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

Multiple Choice Question

QID: 
2

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

 

Multiple Choice Question

QID: 
3

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

Multiple Choice Question

QID: 
4

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

Multiple Choice Question

QID: 
5

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.

Pages