JavaQuizzes

Multiple Choice Question

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

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

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

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

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.

Multiple Choice Question

Given an HttpServletRequest request and HttpResponse response, which sets a cookie “username” with the value “john” in a servlet?

A. request.addCookie("username", "john")
B. request.setCookie("username", "john")
C. response.addCookie("username", "john")
D. request.addHeader(new Cookie("username", "john"))
E. request.addCookie(new Cookie("username", "john"))
F. response.addCookie(new Cookie("username", "john"))
G. response.addHeader(new Cookie("username", "john"))

Multiple Choice Question

Which annotation enables a servlet to efficiently process requests of typo multipart/form-data that
involve large files being uploaded by the client?
A. @AcceptMultipart
B. @MultiPartConfig
C. @MultiPartFormData
D. @WebServlet (multipart = true

Multiple Choice Question

How can you ensure that data is updated in a thread safe manner without using singieThreadModel?

Select 2
A. Store the data in a local variable.
B. Store the data in an instance variable.
C. Store the data in the Httpsession object.
D. Store the data in the sarvletContext object.
E. Store the data in the ServletRequest object.

Multiple Choice Question

Given an HttpServletRequest request and an httpServletResponse response:

HttpSession session = null;
/ / insert code here
if (session = = null) {
/ / do something if session does not exist
} else {
/ / do something if session exists
}

Which of the code below is more appropriate to be inserted instead of the line that contains '/ / insert code here' ?

A. session = response.getSession ();
B. session = request.getSession ();
C. session = request.getSession (true);
D. session = request.getSession (false);
E. session = request.getSession (“jsessionid”);
 

Multiple Choice Question

Which interface must a class implement so that instances of the class are notified after any object added to a session?
A. javax.servlet.http.HttpSessionListener
B. javax.servlet.http.HttpSessionValueListener
C. javax.servlet.http.HttpSessionBindingListener
D. javax.servlet.http.HttpSessionAttributeListener

Pages

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!