Java Programming Fundamentals

Test your knowledge of core Java programming concepts including OOP, collections, threading, exception handling, and basic language features

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What happens when you compare two primitives of different numerical types?

  1. compiler error
  2. smaller type is promoted
  3. must explicitly cast
  4. none of the above
Question 2 True/False

Are you allowed to have more than one top-level(non-inner) class definition per source file?

  1. True
  2. False
Question 3 Multiple Choice (Single Answer)

Assume the bit pattern of byte x is: 10110001. What will the sign of x be after x>>2?

  1. postive
  2. negative
  3. can't be find
  4. none of the above
Question 4 True/False

A class can define two methods with the same name as long as the return types are different

  1. True
  2. False
Question 5 Multiple Choice (Single Answer)

All exceptions inherit from

  1. java.lang.Exception
  2. java.lang.Error
  3. java.lang.Throwable
  4. none of the above
Question 6 Multiple Choice (Single Answer)

What happens when you compare two primitives of different numerical types?

  1. compiler error
  2. smaller type is promoted
  3. must explicitly cast
  4. none of the above
Question 7 Multiple Choice (Single Answer)

public static void main(String [] args) { int x = 5; boolean b1 = true; boolean b2 = false; if ((x == 4) && !b2 ) System.out.print("1 "); System.out.print("2 "); if ((b2 = true) && b1 ) System.out.print("3 "); } } What is the result?

  1. 1,3
  2. 2,3
  3. Compilation Error
  4. Exception
Question 8 Multiple Choice (Single Answer)

interface I{ void f1(); // 1 public void f2(); // 2 protected void f3(); // 3 private void f4(); // 4 } which lines generate compile time errors?

  1. compiletime error at lines 1,2,3,4
  2. compiletime error at line 3
  3. compiletime error at line 1
  4. compiletime error at lines 3,4
Question 9 Multiple Choice (Single Answer)

class C1{ public void m1(){ // 1 } } class C2 extends C1{ //2 private void m1(){ } }

  1. compile time error at line1
  2. compile time error at line2
  3. Run time exception
  4. None Of the above
Question 10 Multiple Choice (Single Answer)

class A extends Thread { public void run() { System.out.print("A"); } } class B { public static void main (String[] args) { A a = new A(); a.start(); a.start(); // 1 } }

  1. Run Time Exception
  2. Compile Error
  3. the code compile and runs fail
  4. None of the above
Question 11 Multiple Choice (Single Answer)

What type of inheritance does Java have?

  1. Single Inheritence
  2. Double Inheritence
  3. Multiple Inheritence
  4. Class Inheritence
Question 12 Multiple Choice (Single Answer)

Java runs on.

  1. Windows
  2. Unix
  3. Solaris
  4. All of the above
Question 13 True/False

The Java interpreter is used for the execution of the source code.

  1. True
  2. False
Question 14 Multiple Choice (Multiple Answers)

A Vector is declared as follows. What happens if the code tried to add 6 th element to this Vector new vector(5,10)

  1. The element will be successfully added
  2. ArrayIndexOutOfBounds Exception
  3. The Vector allocates space to accommodate up to 15 elements
  4. None of the above
Question 15 Multiple Choice (Single Answer)

Which is the data structure used to store sorted map elements

  1. HashSet
  2. Hashmap
  3. Map
  4. TreeMap
Question 16 Multiple Choice (Single Answer)

Which of the following is true ?

  1. Stateless session beans doesn’t preserve any state across method calls
  2. Stateful session beans can be accesses by multiple users at the same time
  3. None of the above
  4. Allof the above
Question 17 Multiple Choice (Single Answer)

Stateful Session beans contain

  1. Home Interface
  2. Remote Interface
  3. Bean Class
  4. All of the above
Question 18 Multiple Choice (Multiple Answers)

A method is defined in a class as : void processUser(int i) { } If this method is overriden in a sub class,

  1. the new method should return int
  2. the new method can return any type of values
  3. the argument list of new method should exactly match that of overriden method
  4. the return type of new method should exactly match that of overriden method
Question 19 Multiple Choice (Single Answer)

What is the output of following piece of code ? int x = 2; switch (x) { case 1:System.out.println(”1?); case 2: case 3:System.out.println(”3?); case 4: case 5:System.out.println(”5?);

  1. No output
  2. 3 and 5
  3. 1, 3 and 5
  4. 3
Question 20 Multiple Choice (Single Answer)

In the init(ServletConfig) method of Servlet life cycle, what method can be used to access the ServletConfig object

  1. getServletInfo()
  2. getInitParameters()
  3. getServletConfig()
  4. None of the above