NEW
Font size
WorksheetsJava Programming Quiz 1
Total questions: 25
Worksheet time: 25mins
Which of the following is not a feature of Java?
Platform independence
Multiple inheritance through classes
Automatic garbage collection
Security features
Java uses which character to terminate statements?
.
:
;
#
What will this output? System.out.println("Hello " + 1 + 2);
Hello 3
Hello 12
Hello 1 2
Compilation Error
Which keyword is used to define a constant value in Java?
static
final
const
constant
Java bytecode is interpreted by:
JVM
JRE
JDK
JavaScript
Best data type for Unicode character?
int
char
byte
String
Output of this code? int[] arr = new int[3]; System.out.println(arr[0]);
Compilation Error
0
null
Garbage value
Which is not a valid variable name?
totalValue
_value
1value
value_1
Widening conversion example?
int to byte
long to int
int to long
float to short
What does this produce? String s = null; System.out.println(s.length());
0
null
Compilation Error
NullPointerException
Result of: 5 + 2 * 3?
21
11
15
10
Output of loop? for (int i = 0; i < 3; i++) { if (i == 1) continue; System.out.print(i); }
012
02
01
123
Logical AND operator in Java?
&
&&
|
||
Ternary operator is used to:
Require only two operands
Return a Boolean result
Replace simple if-else
Throw exception if false
Statement that exits a loop?
break
continue
exit
return
True statement about constructors:
Constructors can return values
Constructors are inherited
Name must match class name
Constructors can be static
What's the output of this code? class Test { Test(int x) { System.out.println("Constructor: " + x); } } Test t = new Test();
Constructor: 0
Compilation Error
Runtime Error
No Output
Method overloading depends on:
Method name and access modifier
Return type only
Number and type of parameters
None of the above
Keyword for class-level members?
fixed
static
final
constant
Which keyword is used to create objects?
new
super
static
class
Output of the following code? class A { void show() { System.out.println("A"); } } class B extends A { void show() { System.out.println("B"); } } A obj = new B(); obj.show();
A
B
Compilation Error
Runtime Error
Keyword to invoke superclass constructor?
super()
this()
base()
init()
Not true about abstract class:
Can have constructors
Can contain concrete methods
Can be instantiated
Can contain static methods
Output of inner class usage? class Outer { class Inner { void display() { System.out.println("Inner"); } } } Outer o = new Outer(); Outer.Inner i = o.new Inner(); i.display();
Compilation Error
Inner
Outer
Runtime Error
Java supports single inheritance through:
Interfaces
Abstract classes
Superclass
Class hierarchy
