Java Programming Fundamentals

Test your knowledge of Java programming fundamentals including control structures, memory management, exception handling, and object-oriented programming concepts.

20 Questions Published

Questions

Question 1 Multiple Choice (Multiple Answers)

Consider the following piece of code: 1 long i = 2 ; 2 switch (i) { 3 case 1: 4 System.out.println ("Case 1"); 5 case 2: 6 System.out.println ("Case 2"); 7 case 3: 8 System.out.println ("Case 3"); 9 default: 10 System.out.println ("Default"); 11 } Which of the following lines will be included in the output? (Choose all that apply, please bear with code as formating it sems is not possible,first numbers represent line numbers)

  1. Case 1
  2. Case 2
  3. Case 3
  4. Default
  5. Compiler Error
Question 2 True/False

In Java the compiler will always insert a default , no argument constructor into any class definition

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

In a method call when an object reference is passed as an argument , So what gets passed actually ?

  1. The object itself
  2. a copy of reference
  3. the original reference
  4. a reference to a copy
Question 4 True/False

In Java if an arithmetic operation is performed then , In case the operands are of different types the resulting type is always the widest of two types

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

consider the following scenarioint i = 0;if ( i ) {System.out.println("This won't print");}else{System.out.println("This prints");}

  1. This won't print
  2. This prints
  3. There's a runtime exception
  4. scenario is not legal
Question 6 True/False

A constructor can be declared abstract

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

The legal values for a boolean in java are choose all that applies

  1. 1,0
  2. TRUE,FALSE
  3. true , false , TRUE,FALSE
  4. true , false
Question 8 True/False

Its possible for a non-abstract class to have abstract methods.

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

The following statement would allocate memory on? char *ptr = malloc(10);

  1. Stack
  2. Heap
  3. Code Segment
  4. Data Segment
Question 10 Multiple Choice (Single Answer)

In the following code variable test would be created on? static int test;

  1. Heap
  2. Stack
  3. Code Segment
  4. Data Segment
Question 11 Multiple Choice (Single Answer)

In the following code variable test1 would be allocated memory on?int func(){int test1 = 10;return test1;}void main(){ int i = 0; i = func();}

  1. Heap
  2. Stack
  3. Code Segment
  4. Data Segment
Question 12 Multiple Choice (Single Answer)

In the following segments which is the read only segment?

  1. Heap
  2. Stack
  3. Code Segment
  4. Data Segment
Question 13 True/False

Can we change the content of string letral?

  1. True
  2. False
Question 14 True/False

Can a constructor be declared as private?

  1. True
  2. False
Question 15 True/False

The access modifier of an overloaded method is different. Is this valid?

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

The following code is compiled: double abc = 100.0; double xyz = abc/0; What is the result?

  1. Compilation Error
  2. Arithmetic Exception
  3. Compiles with no errors
  4. None of the above
Question 17 Multiple Choice (Single Answer)

Consider the following case: A return statement is there in the catch block. An exception occurs and is caught. Now will the finally block be executed?

  1. will execute
  2. will not execute
  3. Compilation Error
  4. Runtime Exception
Question 18 True/False

Overloaded methods should not throw new checked exceptions that have not been thrown by the original method?

  1. True
  2. False
Question 19 True/False

Consider the following case: A = false B = true; What is the result of A && B ?

  1. True
  2. False
Question 20 True/False

Consider the following case; int i; int k; for(i=0;k<10;i++){/* The body */} This will not compile?

  1. True
  2. False