Java Programming Fundamentals
Test your knowledge of core Java programming concepts including OOP, exceptions, garbage collection, data types, and AWT components.
Questions
What modifiers may be used with an interface declaration
- Public
- Private
- Abstract
- Protected
The developer can force garbage collection by calling System.gc().
- True
- False
Assertions are used to enforce all but which of the following?
- Preconditions
- Postconditions
- Exceptions
- Class invariants
Which of the following keywords is used to invoke a method in the parent class?
- this
- super
- final
- static
The following line of code is valid. int x = 9; byte b = x;
- True
- False
At first JAVA was named as______ .
- Fusion
- Gabriel
- Oak
- Globe
A lock can be acquired in a class.
- True
- False
Garbage collection guarantee that a program will not run out of memory.
- True
- False
What is the purpose of the Runtime class?
- To provide access to the Java runtime system.
- To avoid run time exception.
- To provide the capability to execute code no matter whether or not an exception is thrown or caught.
- Both 2 & 3
Which containers may have a MenuBar?
- Panel
- Frame
- Class
- JVM
Can a Byte object be cast to a double value?
- True
- False
A class inherit the constructors of its superclass?
- True
- False
Which abstract class is the super class of all classes used for writing characters. Select the one correct answer.
- FileWriter
- CharWriter
- Writer
- OutputStream
- FileOutputStream
Checked Exceptions are
- all sub-classes of Throwable
- not the sub classes of RuntimeException
- all sub-classes of Error
- None of these
Which class is the immediate superclass of the Container class?
- Frame
- Component
- Public
- Super
class test{} class tester extends test{ public static void main(String[] args) { test t1 = new tester(); test t2 = new test(); tester t3 = new tester(); System.out.println( t1 instanceof tester); System.out.println( t2 instanceof tester); System.out.println( t3 instanceof tester); System.out.println( t1 instanceof test); System.out.println( t2 instanceof test); System.out.println( t3 instanceof test); }
- True False True True True True
- True False False True True True
- True False True True True False
- True False True True False True
public class Fun { public static void main(String[] args){ int x=0; boolean b=true; String str; str=(b)?"success": (x=0)?"Failure":"Neither"; System.out.println(str); } }
- Failure
- success
- Exception will be thrown
- Compilation error
- Neither
class Root { int bark=10; public void get(){ System.out.println("Root"); } } public class Tree extends Root{ public void get(){ bark =15; System.out.println("Tree"); } public static void main(String[] args){ Tree t = new Tree(); Root r = new Root(); Root t1= new Tree(); r.get(); t.get(); t1.get(); System.out.println(t.bark); System.out.println(t1.bark); System.out.println(r.bark); } }
- Root Tree Tree 15 15 15
- Root Tree Tree 10 15 15
- Root Tree Root 15 15 10
- Root Tree Tree 15 15 10
- Root Tree Tree 15 10 10
public class Top { private int i; Top(int i) {this.i=i; } public int getValue(){ return this.i; } } class Bottom{ public static void main(String[] args) { Top tp = new Top(5); String j = Integer.toString(tr.getValue()); tp.i=15; System.out.println( tp.i + j); } }
- 155
- Compilation error
- Exception
- 20
- 5 5
public class Play { public static void main(String[] args) { int[][] a = {{5,2,4,7}, {9,2}, {3,4}}; int[] b = a[1]; int[][] b1= new int[3][]; int a2 = b[2]; System.out.println(a2); } }
- 2
- 4
- Exception
- Compilation error
- 9