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.
Questions
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); }
- DispatcherNotFoundException.
- Runtime error because of incorrectly formed parameter to getNamedDispatcher() method.
- NullPointerException.
- ServletB can obtain request attribute javax.servlet.forward.request_uri.
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"); } }
- Compiler Error
- I am in Constructor
- Message Hello
- Exception
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"); } }
- Exception
- Compiler Error
- I am in Constructor
- Message Hello
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); } }
- Exception
- Compiler Error
- p = 0
- p=10
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); } }
- I am in Constructor p = 10
- I am in Constructor p = 0
- Compiler Error
- Exception
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); } }
- Compiler Error
- Exception
- p = 0
- p=10
________ is the physical aspect of the computer that can be seen.
- Hardware
- Software
- Operating system
- Application program
________ is the physical aspect of the computer that can be seen.
- Hardware
- Software
- Operating system
- Application program
__________ represents an entity in the real world that can be distinctly identified.
- A class
- An object
- A method
- A data field
_______ is a construct that defines objects of the same type.
- A class
- An object
- A method
- A data field
An object is an instance of a __________.
- program
- class
- method
- data