Java Programming Fundamentals with C++ Concepts

A comprehensive quiz covering Java programming basics including access modifiers, identifiers, Java ME, arrays, type conversion, exception handling, and OOP concepts, along with some C++ programming questions about memory allocation, virtual functions, and inheritance.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

class A <- class B class A <- class C class D <- class B,class C class A { public:int a; } class B:public class A { public:int b; } class C : public class A { public:int c } main() { D d1; d1.a=10; int ptr = (int)&d1; cout<<d1.a<<ptr<<(ptr+2); d1=ptr+2; cout<<*ptr; }

  1. 10,10,garbage,garbage
  2. error
  3. error because of ambiguty
  4. garbage,10,10,garbage
Question 2 True/False

Can the private data members of a class be modified or accessed outside the class, without using member functions.

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

Why virtual functions are used ?

  1. To access derived class objects using base class pointer.
  2. To access base class objects using derived class pointer.
  3. To avoid ambiguity in inheritance.
  4. To create array of objects.
Question 4 Multiple Choice (Single Answer)

try{ throw int;} catch (float) catch (double) catch (int) catch (long) catch (...)

  1. catch (float)
  2. catch (...)
  3. catch (int)
  4. catch (long)
Question 5 Multiple Choice (Single Answer)

How much memory is allocated for objects of a class?

  1. Depending upon data members only
  2. Depending upon constructors, destructors, data members, member functions only.
  3. Depending upon data members and non static member functions only.
  4. Depending upon data members and non static member functions, constructors and destructors only.
  5. None of these
Question 6 Multiple Choice (Single Answer)

What will be outcome of following code? List list = new ArrayList(); list.add(0, new Integer(42)); int total = list.get(0); System.out.println(total);

  1. 42
  2. Compilation Error - Incompatible Type
  3. Runtime Error - Java.lang.ClassCastException
  4. None of above
Question 7 Multiple Choice (Single Answer)

What will be output of following code? package test; import java.lang.Math.PI; public class Main { public static void main(String[] args) { System.out.println(PI); } }

  1. 3.14
  2. Compile time error
  3. Run time error
  4. None of above
Question 8 Multiple Choice (Single Answer)

What will be outcome of following code?

  1. first >> second >>
  2. first >>
  3. Compile time Error
  4. Runtime Error -- ConcurrentModificationException
Question 9 Multiple Choice (Single Answer)

What will be the output following code with executed with command ? >java Main 2 public class Main { private static int a = 2; private static int b; public static void main(String[] args) { b = Integer.parseInt(args[0]); a = a + b; System.out.println("a=" + a); System.out.println("b=" + b); } static{ a = 0; } }

  1. a=4; b=2;
  2. a=2; b=4;
  3. a=0; b=2; *
  4. Run time error
Question 10 Multiple Choice (Single Answer)

What will be the output of following code? 1 public class Main { 2 public static void main(String[] args) { 3 float b = 2.12; 4 b = b + 3.10; 5 System.out.println(b); 6 } 7 }

  1. Compile time error at line 3
  2. Compile time error at line 4
  3. 5.22
  4. None of above
Question 11 Multiple Choice (Single Answer)

What will be output of following code ? 1 public class Main { 2 public static void main(String[] args) { 3 byte b = (int)2.12; 4 b = b + 3; 5 System.out.println(b); 6 } 7 }

  1. Compile time error at line 3
  2. Compile time error at line 4
  3. 5
  4. None
Question 12 Multiple Choice (Single Answer)

What will be output of following code? 1 public class Main { 2 public static void main(String[] args) { 3 short a = 22; 4 execute(3); 5 System.out.println(a); 6 } 7 8 static void execute(short s){ 9 s = 33; 10 } 11 }

  1. Compile time error at line 3
  2. Compile time error at line 4
  3. 22
  4. None of above
Question 13 Multiple Choice (Multiple Answers)

What will be output of following code? 1 double d = 10.10/0.0; 2 int i = 10/0;

  1. Compile time error
  2. Runtime error at line 1
  3. Runtime error at line 2
  4. Runtime error at line 1 & 2
Question 14 Multiple Choice (Multiple Answers)

Select the key words, which can not be used to define an identifier.

  1. goto
  2. enum
  3. null
  4. extend
Question 15 Multiple Choice (Single Answer)

What will be the output of following code? public class Main { public static void main(String[] args) { int values[] = {1,2,3,4,5,6,7,8}; for(int i=0;i<8; ++i) System.out.println(values[i++]); } }

  1. 1 3 5 7
  2. 2 4 6 8
  3. 2 3 4 5 6 7 8
  4. None of above
Question 16 Multiple Choice (Single Answer)

MIDP 2.0

  1. JSR 118
  2. JSR 30
  3. JSR 20
  4. JSR 21
Question 17 True/False

SSL connection can be established in JAVA ME based applications.

  1. True
  2. False
Question 18 True/False

JAVA ME applications can remain unsigned.

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

Choose the illegal identifier?

  1. int _a;
  2. int $b;
  3. int _123;
  4. int e#123;
Question 20 Multiple Choice (Single Answer)

Find the odd one?

  1. public
  2. private
  3. protected
  4. abstract