Java Programming and OOP Concepts

Test your knowledge of Java programming fundamentals, including constructors, main methods, servlets, and object-oriented programming concepts like classes and objects.

11 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

From the available options, what is the likely outcome from running the code below? (Choose one.) protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestDispatcher dispatcher = getServletContext().getNamedDispatcher("/ServletB"); dispatcher.forward(request, response); }

  1. DispatcherNotFoundException.
  2. Runtime error because of incorrectly formed parameter to getNamedDispatcher() method.
  3. NullPointerException.
  4. ServletB can obtain request attribute javax.servlet.forward.request_uri.
Question 2 Multiple Choice (Single Answer)

package simplejava; public class TestMain { TestMain() { System.out.println("I am in Constructor"); } TestMain(String message) { System.out.println("Message " + message); } public static void main(String[] args) { TestMain tm = new TestMain(); } public static void main(String args) { TestMain tm = new TestMain("Hello"); } }

  1. Compiler Error
  2. I am in Constructor
  3. Message Hello
  4. Exception
Question 3 Multiple Choice (Single Answer)

package simplejava; public class TestMain1 { TestMain1() { System.out.println("I am in Constructor"); } TestMain1(String message) { System.out.println("Message " + message); } public void main(String[] args) { TestMain1 nm = new TestMain1(); TestMain1 nm1 = new TestMain1("Hello"); } }

  1. Exception
  2. Compiler Error
  3. I am in Constructor
  4. Message Hello
Question 4 Multiple Choice (Single Answer)

package simplejava; public class TestConstructor1 { int p; TestConstructor1() { System.out.println("I am in Constructor"); } TestConstructor1(int p) { this.p =p; System.out.println("p = "+p); this(); } public static void main(String[] args) { TestConstructor1 tp1 = new TestConstructor1(10); } }

  1. Exception
  2. Compiler Error
  3. p = 0
  4. p=10
Question 5 Multiple Choice (Single Answer)

package simplejava; public class TestConstructor2 { int p; TestConstructor2() { System.out.print(" I am in Constructor"); } TestConstructor2(int p) { this(); this.p = p; System.out.print(" p = " + p); } public static void main(String[] args) { TestConstructor2 tp1 = new TestConstructor2(10); } }

  1. I am in Constructor p = 10
  2. I am in Constructor p = 0
  3. Compiler Error
  4. Exception
Question 6 Multiple Choice (Single Answer)

package simplejava; public class TestConstructor { int p ; public void TestConstructor(int p) { this.p=p; } public static void main(String[] args) { TestConstructor tp = new TestConstructor(10); TestConstructor tp = new TestConstructor(); System.out.println("p = "+tp.p); } }

  1. Compiler Error
  2. Exception
  3. p = 0
  4. p=10
Question 7 Multiple Choice (Single Answer)

________ is the physical aspect of the computer that can be seen.

  1. Hardware
  2. Software
  3. Operating system
  4. Application program
Question 8 Multiple Choice (Single Answer)

________ is the physical aspect of the computer that can be seen.

  1. Hardware
  2. Software
  3. Operating system
  4. Application program
Question 9 Multiple Choice (Single Answer)

__________ represents an entity in the real world that can be distinctly identified.

  1. A class
  2. An object
  3. A method
  4. A data field
Question 10 Multiple Choice (Single Answer)

_______ is a construct that defines objects of the same type.

  1. A class
  2. An object
  3. A method
  4. A data field
Question 11 Multiple Choice (Single Answer)

An object is an instance of a __________.

  1. program
  2. class
  3. method
  4. data