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.
Questions
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; }
- 10,10,garbage,garbage
- error
- error because of ambiguty
- garbage,10,10,garbage
Can the private data members of a class be modified or accessed outside the class, without using member functions.
- True
- False
Why virtual functions are used ?
- To access derived class objects using base class pointer.
- To access base class objects using derived class pointer.
- To avoid ambiguity in inheritance.
- To create array of objects.
try{ throw int;} catch (float) catch (double) catch (int) catch (long) catch (...)
- catch (float)
- catch (...)
- catch (int)
- catch (long)
How much memory is allocated for objects of a class?
- Depending upon data members only
- Depending upon constructors, destructors, data members, member functions only.
- Depending upon data members and non static member functions only.
- Depending upon data members and non static member functions, constructors and destructors only.
- None of these
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);
- 42
- Compilation Error - Incompatible Type
- Runtime Error - Java.lang.ClassCastException
- None of above
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); } }
- 3.14
- Compile time error
- Run time error
- None of above
What will be outcome of following code?
- first >> second >>
- first >>
- Compile time Error
- Runtime Error -- ConcurrentModificationException
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; } }
- a=4; b=2;
- a=2; b=4;
- a=0; b=2; *
- Run time error
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 }
- Compile time error at line 3
- Compile time error at line 4
- 5.22
- None of above
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 }
- Compile time error at line 3
- Compile time error at line 4
- 5
- None
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 }
- Compile time error at line 3
- Compile time error at line 4
- 22
- None of above
What will be output of following code? 1 double d = 10.10/0.0; 2 int i = 10/0;
- Compile time error
- Runtime error at line 1
- Runtime error at line 2
- Runtime error at line 1 & 2
Select the key words, which can not be used to define an identifier.
- goto
- enum
- null
- extend
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 3 5 7
- 2 4 6 8
- 2 3 4 5 6 7 8
- None of above
MIDP 2.0
- JSR 118
- JSR 30
- JSR 20
- JSR 21
SSL connection can be established in JAVA ME based applications.
- True
- False
JAVA ME applications can remain unsigned.
- True
- False
Choose the illegal identifier?
- int _a;
- int $b;
- int _123;
- int e#123;
Find the odd one?
- public
- private
- protected
- abstract