Java Practice Questions and Mcqs
Java Practice Questions and Mcqs
Constructor of
Access A executes
Specifiers class A, B and C are in multilevel inheritance first, followed
Constructors hierarchy repectively . In the main method of by the
Methods some other class if class C object is created, in constructor of
NewQB what sequence the three constructors execute? MCQ B and C
Consider the following code and choose the
correct option:
Access package aj; private class S{ int roll;
Specifiers S(){roll=1;} }
Constructors package aj; class T
Methods { public static void main(String ar[]){ Compilation
NewQB System.out.print(new S().roll);}} MCQ error
Given:
public class Yikes {
class Order{
Order(){
System.out.println("Cat");
}
public static void main(String... Args){
System.out.println("Ant");
}
static{
System.out.println("Dog");
}
Access {
Specifiers System.out.println("Man");
Constructors }}
Methods consider the code above & select the proper
NewQB output from the options. MCQ Dog Ant
class One{
int var1;
One (int x){
var1 = x;
}}
class Derived extends One{
int var2;
void display(){
System.out.println("var
1="+var1+"var2="+var2);
}}
class Main{
public static void main(String[] args){
Access Derived obj = new Derived();
Specifiers obj.display();
Constructors }}
Methods consider the code above & select the proper
NewQB output from the options. MCQ 0,0
class Meal {
Meal() {
System.out.println("Meal()");
}
}
class Cheese {
Cheese() {
System.out.println("Cheese()");
}
}
class Lunch extends Meal {
Lunch() {
System.out.println("Lunch()");
}
}
class PortableLunch extends Lunch {
PortableLunch() {
System.out.println("PortableLunch()");
}
}
class Sandwich extends PortableLunch {
private Cheese c = new Cheese();
public Sandwich() {
System.out.println("Sandwich()");
}
}
Access public class MyClass7 { Meal()
Specifiers public static void main(String[] args) { Lunch()
Constructors new Sandwich(); PortableLunch
Methods } () Cheese()
NewQB } What would be the output? MCQ Sandwich()
The compiler
will
Access automatically
Specifiers change the
Constructors What will happen if a main() method of a private
Methods "testing" class tries to access a private instance variable to a
NewQB variable of an object using dot notation? MCQ public variable
public class Q {
Access public static void main(String argv[]) { Compiler
Specifiers int anar[] = new int[] { 1, 2, 3 }; Error: anar is
Constructors System.out.println(anar[1]); referenced
Methods } before it is
NewQB } MCQ initialized
Access
Specifiers
Constructors
Methods A constructor may return value including class
NewQB type MCQ true
class MyClass1
{
private int area(int side)
{
return(side * side);
}
public static void main(String args[ ])
{
MyClass1 MC = new MyClass1( );
Access int area = MC.area(50);
Specifiers System.out.println(area);
Constructors }
Methods } Compilation
NewQB What would be the output? MCQ error
public class c1 {
private c1()
{
System.out.println("Hello");
}
public static void main(String args[])
{
Access c1 o1=new c1();
Specifiers }
Constructors }
Methods
NewQB What is the output? MCQ Hello
Access
Specifiers
Constructors Which modifier indicates that the variable might
Methods be modified asynchronously, so that all threads
NewQB will get the correct value of the variable. MCQ synchronized
class A {
int i, j;
A(int a, int b) {
i = a;
j = b;
}
void show() {
System.out.println("i and j: " + i + " " + j);
}
}
class B extends A {
int k;
class Order{
Order(){
System.out.println("Cat");
}
public static void main(String... Args){
Order obj = new Order();
System.out.println("Ant");
}
Access static{
Specifiers System.out.println("Dog");
Constructors }}
Methods consider the code above & select the proper
NewQB output from the options. MCQ Cat Ant Dog
What will be the result when you attempt to
compile this program?
public class Rand{
public static void main(String argv[]){
Access int iRand;
Specifiers iRand = Math.random(); Compile time
Constructors System.out.println(iRand); error referring
Methods } to a cast
NewQB } MCQ problem
Annotations_ Choose the meta annotations. (Choose
NewQB THREE) MCA Override
If no retention policy is specified for an
Annotations_ annotation, then the default policy of
NewQB __________ is used. MCQ method
Select the variable which are in
Annotations_ java.lang.annotation.RetentionPolicy class.
NewQB (Choose THREE) MCA SOURCE
Information
Annotations_ Select the Uses of annotations. (Choose For the
NewQB THREE) MCA Compiler
Given:
10. interface A { void x(); }
11. class B implements A {
public void x() { }
public void y() { } }
12. class C extends B {
public void x() {} }
And:
20. java.util.List<a> list = new
java.util.ArrayList</a>();
21. list.add(new B());
22. list.add(new C());
23. for (A a:list) {
24. a.x(); Compilation
25. a.y();; fails because
Collections_ut 26. } of an error in
il_NewQB What is the result? MCQ line 25
Given:
public static Collection get() {
Collection sorted = new LinkedList();
sorted.add("B"); sorted.add("C");
sorted.add("A");
return sorted;
}
public static void main(String[] args) {
for (Object obj: get()) {
System.out.print(obj + ", ");
}
Collections_ut }
il_NewQB What is the result? MCQ A, B, C,
import java.util.StringTokenizer;
class ST{
public static void main(String[] args){
String input = "Today is$Holiday";
StringTokenizer st = new
StringTokenizer(input,"$");
while(st.hasMoreTokens()){
Collections_ut System.out.println(st.nextElement()); Today is
il_NewQB }} MCQ Holiday
Given:
public static Iterator reverse(List list) {
Collections.reverse(list);
return list.iterator();
}
public static void main(String[] args) {
List list = new ArrayList();
list.add("1"); list.add("2"); list.add("3");
for (Object obj: reverse(list))
System.out.print(obj + ", ");
Collections_ut }
il_NewQB What is the result? MCQ 3, 2, 1,
System.out.println(set.equals(set2));
Collections_ut }
il_NewQB } What is the result of given code? MCQ true
1) TreeSet
2) HashMap
Collections_ut 3) LinkedList
il_NewQB 4) an array MCQ 1
Given:
public class Test {
public enum Dogs {collie, harrier};
public static void main(String [] args) {
Dogs myDog = Dogs.collie;
switch (myDog) {
case collie:
System.out.print("collie ");
Control case harrier:
structures System.out.print("harrier ");
wrapper }
classes auto }
boxing }
NewQB What is the result? MCQ collie
Given:
public class Test {
public enum Dogs {collie, harrier, shepherd};
public static void main(String [] args) {
Dogs myDog = Dogs.shepherd;
switch (myDog) {
case collie:
System.out.print("collie ");
case default:
System.out.print("retriever ");
Control case harrier:
structures System.out.print("harrier ");
wrapper }
classes auto }
boxing }
NewQB What is the result? MCQ harrier
Given:
static void myFunc()
{
int i, s = 0;
for (int j = 0; j < 7; j++) {
i = 0;
do {
i++;
Control s++;
structures } while (i < j);
wrapper }
classes auto System.out.println(s);
boxing }
NewQB } What would be the result MCQ 20
Control
structures
wrapper
classes auto What is the range of the random number r
boxing generated by the code below?
NewQB int r = (int)(Math.floor(Math.random() * 8)) + 2; MCQ 2 <= r <= 9
class Test{
public static void main(String[] args) {
int x=-1,y=-1;
if(++x=++y)
System.out.println("R.T. Ponting");
Control else
structures System.out.println("C.H. Gayle");
wrapper }
classes auto }
boxing consider the code above & select the proper
NewQB output from the options. MCQ R.T.Ponting
Given:
public class Breaker2 {
static String o = "";
public static void main(String[] args) {
z:
for(int x = 2; x < 7; x++) {
if(x==3) continue;
if(x==5) break z;
Control o = o + x;
structures }
wrapper System.out.println(o);
classes auto }
boxing }
NewQB What is the result? MCQ 2
Given:
public class Batman {
int squares = 81;
public static void main(String[] args) {
new Batman().go();
}
void go() {
Control incr(++squares);
structures System.out.println(squares);
wrapper }
classes auto void incr(int squares) { squares += 10; }
boxing }
NewQB What is the result? MCQ 81
public void foo( boolean a, boolean b)
{
if( a )
{
System.out.println("A"); /* Line 5 */
}
else if(a && b) /* Line 7 */
{
System.out.println( "A && B");
}
else /* Line 11 */
{
if ( !b )
{
System.out.println( "notB") ;
}
else
{
Control System.out.println( "ELSE" ) ;
structures }
wrapper } If a is true and
classes auto } b is false then
boxing the output is
NewQB What would be the result? MCQ "notB"
Control
structures
wrapper
classes auto
boxing Which of the following statements are true String is a
NewQB regarding wrapper classes? (Choose TWO) MCA wrapper class
Given:
class Atom {
Atom() { System.out.print("atom "); }
}
class Rock extends Atom {
Rock(String type) { System.out.print(type); }
}
public class Mountain extends Rock {
Mountain() {
super("granite ");
Control new Rock("granite ");
structures }
wrapper public static void main(String[] a) { new
classes auto Mountain(); }
boxing } Compilation
NewQB What is the result? MCQ fails.
What are the thing to be placed to complete the
code?
class Wrap {
public static void main(String args[]) {
Given:
public class Barn {
public static void main(String[] args) {
new Barn().go("hi", 1);
new Barn().go("hi", "world", 2);
Control }
structures public void go(String... y, int x) {
wrapper System.out.print(y[y.length - 1] + " ");
classes auto }
boxing }
NewQB What is the result? MCQ hi hi
Consider the following code and choose the
correct option:
class Test{
Control public static void main(String args[]){ int
structures x=034;
wrapper int y=12;
classes auto int ans=x+y;
boxing System.out.println(ans);
NewQB }} MCQ 40
class AutoBox {
public static void main(String args[]) {
int i = 10;
Control Integer iOb = 100;
structures i = iOb;
wrapper System.out.println(i + " " + iOb);
classes auto } No,
boxing } whether this code work properly, if so what Compilation
NewQB would be the result? MCQ error
Control Consider the following code and choose the
structures correct option:
wrapper class Test{
classes auto public static void main(String args[]){
boxing Long l=0l; Compilation
NewQB System.out.println(l.equals(0));}} MCQ error
int I = 0;
outer:
while (true)
{
I++;
inner:
for (int j = 0; j < 10; j++)
{
I += j;
if (j == 3)
continue inner;
break outer;
Control }
structures continue outer;
wrapper }
classes auto System.out.println(I);
boxing
NewQB What will be thr result? MCQ 3
Given:
int n = 10;
switch(n)
{
case 10: n = n + 1;
case 15: n = n + 2;
case 20: n = n + 3;
Control case 25: n = n + 4;
structures case 30: n = n + 5;
wrapper }
classes auto System.out.println(n);
boxing What is the value of ’n’ after executing the
NewQB following code? MCQ 23
Given:
import java.util.*;
public class Explorer3 {
public static void main(String[] args) {
TreeSet<Integer> s = new TreeSet<Integer>();
TreeSet<Integer> subs = new
TreeSet<Integer>();
for(int i = 606; i < 613; i++)
if(i%2 == 0) s.add(i);
Control subs = (TreeSet)s.subSet(608, true, 611, true);
structures subs.add(629);
wrapper System.out.println(s + " " + subs);
classes auto }
boxing } Compilation
NewQB What is the result? MCQ fails.
Given:
Float pi = new Float(3.14f);
if (pi > 3) {
System.out.print("pi is bigger than 3. ");
}
else {
Control System.out.print("pi is not bigger than 3. ");
structures }
wrapper finally {
classes auto System.out.println("Have a nice day.");
boxing } Compilation
NewQB What is the result? MCQ fails.
Given:
public void go() {
String o = "";
z:
for(int x = 0; x < 3; x++) {
for(int y = 0; y < 2; y++) {
if(x==1) break;
if(x==2 && y==1) break z;
o = o + x + y;
Control }
structures }
wrapper System.out.println(o);
classes auto }
boxing What is the result when the go() method is
NewQB invoked? MCQ 00
Examine the following code:
int count = 1;
while ( ___________ )
{
System.out.print( count + " " );
count = count + 1;
}
Control System.out.println( );
structures
wrapper What condition should be used so that the code
classes auto prints:
boxing
NewQB 12345678 MCQ count < 9
Given:
int x = 0;
int y = 10;
Control do {
structures y--;
wrapper ++x;
classes auto } while (x < 5);
boxing System.out.print(x + "," + y);
NewQB What is the result? MCQ 5,6
What is the output :
class Test{
public static void main(String[] args) {
int a=5,b=10,c=1;
if(a>c){
System.out.println("success");
Control }
structures else{
wrapper break;
classes auto }
boxing }
NewQB } MCQ success
Given:
double height = 5.5;
if(height-- >= 5.0)
System.out.print("tall ");
if(--height >= 4.0)
System.out.print("average ");
Control if(height-- >= 3.0)
structures System.out.print("short ");
wrapper else
classes auto System.out.print("very short ");
boxing }
NewQB What would be the Result? MCQ tall
Consider the following code and choose the
Control correct option:
structures class Test{
wrapper public static void main(String args[]){
classes auto String hexa = "0XFF";
boxing int number = Integer.decode(hexa); Compilation
NewQB System.out.println(number); }} MCQ error
Control
structures
wrapper
classes auto Person[] p =
boxing Which of the following statements about arrays new
NewQB is syntactically wrong? MCQ Person[5];
import java.util.*;
class I
{
public static void main (String[] args)
{
Control Object i = new ArrayList().iterator();
structures System.out.print((i instanceof List)+",");
wrapper System.out.print((i instanceof Iterator)+",");
classes auto System.out.print(i instanceof ListIterator);
boxing } Prints: false,
NewQB } MCQ false, false
Given:
public static void test(String str) {
int check = 4;
if (check = str.length()) {
System.out.print(str.charAt(check -= 1) +", ");
} else {
System.out.print(str.charAt(0) + ", ");
}
Control }
structures and the invocation:
wrapper test("four");
classes auto test("tee");
boxing test("to");
NewQB What is the result? MCQ r, t, t,
import java.util.SortedSet;
import java.util.TreeSet;
Control
structures
wrapper The return
classes auto type of the
boxing Which statements are true about maps? values()
NewQB (Choose TWO) MCA method is set
Control
structures
wrapper Which collection implementation is suitable for
classes auto maintaining an ordered sequence of
boxing objects,when objects are frequently inserted in
NewQB and removed from the middle of the sequence? MCQ TreeMap
OutputStream
is the abstract
Control superclass of
structures all classes
wrapper that represent
classes auto an
boxing outputstream
NewQB Choose TWO correct options: MCA of bytes.
A continue
Control statement
structures doesn’t
wrapper transfer
classes auto control to the
boxing Which of the following statements is TRUE test statement
NewQB regarding a Java loop? MCQ of the for loop
switch(x)
{
default:
System.out.println("Hello");
}
Which of the following are acceptable types for
x?
Control 1.byte
structures 2.long
wrapper 3.char
classes auto 4.float
boxing 5.Short
NewQB 6.Long MCQ 1 ,3 and 5
Used to
release the
resources
Exception_ha which are
ndling_NewQ Which are true with respect to finally block? obtained in try
B (Choose THREE) MCA block.
Given:
public void testIfA() {
if (testIfB("True")) {
System.out.println("True");
} else {
System.out.println("Not true");
}
}
public Boolean testIfB(String str) {
return Boolean.valueOf(str);
Exception_ha }
ndling_NewQ What is the result when method testIfA is
B invoked? MCQ true
Deadlock will
Exception_ha not occur if
ndling_NewQ Which of the following statements are true? wait()/notify()
B (Choose TWO) MCA is used
public class MyProgram
{
public static void throwit()
{
throw new RuntimeException();
}
public static void main(String args[])
{
try
{
System.out.println("Hello world ");
throwit();
System.out.println("Done with try block
");
}
finally
{
System.out.println("Finally executing ");
}
}
Exception_ha } The program
ndling_NewQ which answer most closely indicates the will not
B behavior of the program? MCQ compile.
If a method is capable of causing an exception
that it does not handle, it must specify this
Exception_ha behavior using throws so that callers of the
ndling_NewQ method can guard themselves against such
B Exception MCQ false
If an
exception is
not caught in
a method,the
method will
terminate and
Exception_ha normal
ndling_NewQ execution will
B Choose TWO correct options: MCA resume
Which four can be thrown using the throw
statement?
1.Error
2.Event
3.Object
Exception_ha 4.Throwable
ndling_NewQ 5.Exception
B 6.RuntimeException MCQ 1, 2, 3 and 4
Given:
class X { public void foo() { System.out.print("X
"); } }
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
Exception_ha System.out.println(" Arithmetic Exception");
ndling_NewQ }
B System.out.println("finished"); MCQ finished
Exception_ha
ndling_NewQ
B Which of the following methods are static? MCA start()
static methods
are difficult to
maintain,
because you
can not
Exception_ha change their
ndling_NewQ Which of the following statements regarding implementatio
B static methods are correct? (2 answers) MCA n.
1.notify();
2.notifyAll();
3.isInterrupted();
4.synchronized();
5.interrupt();
Exception_ha 6.wait(long msecs);
ndling_NewQ 7.sleep(long msecs);
B 8.yield(); MCQ 1, 2, 4
class Trial{
public static void main(String[] args){
try{
System.out.println("One");
int y = 2 / 0;
System.out.println("Two");
}
catch(RuntimeException ex){
System.out.println("Catch");
}
finally{
Exception_ha System.out.println("Finally");
ndling_NewQ } One Two
B }} MCQ Catch Finally
Which digit,and in what order,will be printed
when the following program is run?
class Trial{
public static void main(String[] args){
Exception_ha try{
ndling_NewQ System.out.println("Java is portable"); Java is
B }}} MCQ portable
A static
Exception_ha method
ndling_NewQ cannot be
B Which statement is true? MCQ synchronized.
Given:
public class ExceptionTest
{
class TestException extends Exception {}
public void runTest() throws TestException {}
public void test() /* Line X */
{
runTest();
}
Exception_ha }
ndling_NewQ At Line X, which code is necessary to make the No code is
B code compile? MCQ necessary
Implement
java.lang.Run
Exception_ha nable and
ndling_NewQ Which two can be used to create a new implement the
B Thread? MCA run() method.
A try
statement
must have at
Exception_ha least one
ndling_NewQ corresponding
B Choose the correct option: MCQ catch block
class PropagateException{
public static void main(String[] args){
try{
method();
System.out.println("method() called");
}
catch(ArithmeticException ex){
System.out.println("Arithmetic Exception");
}
catch(RuntimeException re){
System.out.println("Runtime Exception");
}}
static void method(){
int y = 2 / 0;
Exception_ha }}
ndling_NewQ consider the code above & select the proper Arithmetic
B output from the options. MCQ Exception
Given:
static void test() {
try {
String x = null;
System.out.print(x.toString() + " ");
}
finally { System.out.print("finally "); }
}
public static void main(String[] args) {
try { test(); }
catch (Exception ex)
Exception_ha { System.out.print("exception "); }
ndling_NewQ }
B What is the result? MCQ null
Given two programs:
1. package pkgA;
2. public class Abc {
3. int a = 5;
4. protected int b = 6;
5. public int c = 7;
6. }
3. package pkgB;
4. import pkgA.*;
5. public class Def {
6. public static void main(String[] args) {
7. Abc f = new Abc();
8. System.out.print(" " + f.a);
9. System.out.print(" " + f.b);
10. System.out.print(" " + f.c);
11. }
Exception_ha 12. }
ndling_NewQ What is the result when the second program is
B run? (Choose all that apply) MCA 567
System.out.print("Start ");
try
{
System.out.print("Hello world");
throw new FileNotFoundException();
}
System.out.print(" Catch Here "); /* Line 7 */
catch(EOFException e)
{
System.out.print("End of file exception");
}
catch(FileNotFoundException e)
{
System.out.print("File not found");
}
catch(X x) can
catch
subclasses of
Exception_ha X where X is a
ndling_NewQ subclass of
B Which of the following statements is true? MCQ Exception.
Consider the following code and choose the
Exception_ha correct option:
ndling_NewQ int array[] = new int[10]; compiles
B array[-1] = 0; MCQ successfully
Given:
11. class A {
12. public void process()
{ System.out.print("A,"); }
13. class B extends A {
14. public void process() throws IOException {
15. super.process();
16. System.out.print("B,");
17. throw new IOException();
18. }
19. public static void main(String[] args) {
20. try { new B().process(); }
21. catch (IOException e)
Exception_ha { System.out.println("Exception"); }
ndling_NewQ 22. }
B What is the result? MCQ Exception
The notifyAll()
method must
be called from
Exception_ha a
ndling_NewQ synchronized
B Which statement is true? MCQ context
class Trial{
public static void main(String[] args){
try{
System.out.println("Try Block");
}
finally{
Exception_ha System.out.println("Finally Block");
ndling_NewQ }
B }} MCQ Try Block
An object is
deleted as
soon as there
are no more
Garbage_Coll Which statements describe guaranteed references
ection_NewQ behaviour of the garbage collection and that denote
B finalization mechanisms? (Choose TWO) MCA the object
class X2
{
public X2 x;
public static void main(String [] args)
{
X2 x2 = new X2(); /* Line 6 */
X2 x3 = new X2(); /* Line 7 */
x2.x = x3;
x3.x = x2;
x2 = new X2();
x3 = x2; /* Line 11 */
}
}
Garbage_Coll
ection_NewQ after line 11 runs, how many objects are eligible
B for garbage collection? MCQ
Given :
public class MainOne {
public static void main(String args[]) {
String str = "this is java";
System.out.println(removeChar(str,'s'));
}
Set all
references to
the object to
Garbage_Coll new
ection_NewQ How can you force garbage collection of an values(null,
B object? MCQ for example).
Consider the following code and choose the
correct option:
public class X
{
public static void main(String [] args)
{
X x = new X();
X x2 = m1(x); /* Line 6 */
X x4 = new X();
x2 = x4; /* Line 8 */
doComplexStuff(); }
static X m1(X mx) {
mx = new X();
Garbage_Coll return mx; }}
ection_NewQ After line 8 runs. how many objects are eligible
B for garbage collection? MCQ
interface interface_1 {
void f1();
}
class Class_1 implements interface_1 {
void f1() {
System.out.println("From F1 funtion in
Class_1 Class");
}
}
public class Demo1 {
Inheritance_In public static void main(String args[]) {
terfaces_Abstr Class_1 o11 = new Class_1();
act o11.f1(); From F1
Classes_New } function in
QB } MCQ Class_1 Class
Given:
class A {
final void meth() {
System.out.println("This is a final method.");
}
}
class B extends A {
void meth() {
System.out.println("Illegal!");
}
}
class MyClass8{
public static void main(String[] args) {
A a = new A();
Inheritance_In a.meth();
terfaces_Abstr B b= new B();
act b.meth();
Classes_New } This is a final
QB }What would be the result? MCQ method illegal
class SuperClass
{
public Integer getLength()
{
return new Integer(4);
}
}
Given :
What would be the result of compiling and
running the following program?
// Filename: MyClass.java
public class MyClass {
public static void main(String[] args) {
C c = new C();
System.out.println(c.max(13, 29));
}
}
class A {
int max(int x, int y) { if (x>y) return x; else return
y; } The code will
} fail to compile
class B extends A{ because the
int max(int x, int y) { return super.max(y, x) - 10; max() method
} in B passes
Inheritance_In } the arguments
terfaces_Abstr class C extends B { in the call
act int max(int x, int y) { return super.max(x+10, super.max(y,
Classes_New y+10); } x) in the
QB } MCQ wrong order.
class Animal {
void makeNoise() {System.out.println("generic
noise"); }
}
class Dog extends Animal {
void makeNoise() {System.out.println("bark"); }
void playDead() { System.out.println("roll over");
}
}
class CastTest2 {
public static void main(String [] args) {
Dog a = (Dog) new Animal();
Inheritance_In a.makeNoise();
terfaces_Abstr }
act }
Classes_New consider the code above & select the proper
QB output from the options. MCQ run time error
Consider the following code and choose the
correct option:
interface employee{
void saldetails();
void perdetails();
}
abstract class perEmp implements employee{
public void perdetails(){
System.out.println("per details"); }}
class Programmer extends perEmp{
public void saldetails(){
Inheritance_In perdetails();
terfaces_Abstr System.out.println("sal details"); }
act public static void main(String[] args) {
Classes_New perEmp emp=new Programmer();
QB emp.saldetails(); }} MCQ sal details
class Money {
private String country = "Canada";
Inheritance_In public String getC() { return country; } }
terfaces_Abstr class Yen extends Money {
act public String getC() { return super.country; }
Classes_New public static void main(String[] args) {
QB System.out.print(new Yen().getC() ); } } MCQ Canada
we must use
always
Inheritance_In extends and
terfaces_Abstr later we must
act When we use both implements & extends use
Classes_New keywords in a single java program then what is implements
QB the order of keywords to follow? MCQ keyword.
Given:
interface DeclareStuff {
public static final int Easy = 3;
void doStuff(int t); }
public class TestDeclare implements
DeclareStuff {
public static void main(String [] args) {
int x = 5;
new TestDeclare().doStuff(++x);
}
Inheritance_In void doStuff(int s) {
terfaces_Abstr s += Easy + ++s;
act System.out.println("s " + s);
Classes_New }
QB } What is the result? MCQ s 14
Given:
interface A { public void methodA(); }
interface B { public void methodB(); }
interface C extends A,B{ public void methodC();
} //Line 3
class D implements B {
public void methodB() { } //Line 5
}
class E extends D implements C { //Line 7
Inheritance_In public void methodA() { }
terfaces_Abstr public void methodB() { } //Line 9 Compilation
act public void methodC() { } fails, due to
Classes_New } an error in line
QB What would be the result? MCQ 3
Inheritance_In
terfaces_Abstr It can only be
act used in the
Classes_New Which of the following statements is true parent's
QB regarding the super() method? MCQ constructor
Given:
11. class ClassA {}
12. class ClassB extends ClassA {}
13. class ClassC extends ClassA {}
and:
21. ClassA p0 = new ClassA();
Inheritance_In 22. ClassB p1 = new ClassB();
terfaces_Abstr 23. ClassC p2 = new ClassC();
act 24. ClassA p3 = new ClassB();
Classes_New 25. ClassA p4 = new ClassC();
QB Which TWO are valid? (Choose two.) MCA p0 = p1;
class Animal {
void makeNoise() {System.out.println("generic
noise"); }
}
class Dog extends Animal {
void makeNoise() {System.out.println("bark"); }
void playDead() { System.out.println("roll over");
}
}
class CastTest2 {
public static void main(String [] args) {
Animal a = new Dog();
Inheritance_In a.makeNoise();
terfaces_Abstr }
act }
Classes_New consider the code above & select the proper
QB output from the options. MCQ run time error
Given :
No—there
Day d; must always
Inheritance_In BirthDay bd = new BirthDay("Raj", 25); be an exact
terfaces_Abstr d = bd; // Line X match
act between the
Classes_New Where Birthday is a subclass of Day. State variable and
QB whether the code given at Line X is correct: MCQ the object
A super() or
this() call must
always be
provided
Inheritance_In explicitly as
terfaces_Abstr the first
act statement in
Classes_New the body of a
QB Select the correct statement: MCQ constructor.
Inheritance_In
terfaces_Abstr public final
act data type
Classes_New Choose the correct declaration of variable in an varaibale=intia
QB interface: MCQ lization;
interface Vehicle{
void drive();
}
final class TwoWheeler implements Vehicle{
int wheels = 2;
public void drive(){
System.out.println("Bicycle");
}
}
class ThreeWheeler extends TwoWheeler{
public void drive(){
System.out.println("Auto");
}}
class Test{
public static void main(String[] args){
Inheritance_In ThreeWheeler obj = new ThreeWheeler();
terfaces_Abstr obj.drive();
act }}
Classes_New consider the code above & select the proper
QB output from the options. MCQ Auto
Consider the following code and choose the
correct option:
interface employee{
void saldetails();
void perdetails();
}
abstract class perEmp implements employee{
public void perdetails(){
Inheritance_In System.out.println("per details"); }}
terfaces_Abstr class Programmer extends perEmp{
act public static void main(String[] args) {
Classes_New perEmp emp=new Programmer();
QB emp.saldetails(); }} MCQ sal details
Inheritance_In
terfaces_Abstr
act
Classes_New abstract and
QB All data members in an interface are by default MCQ final
An abstract
class is one
Inheritance_In which
terfaces_Abstr contains
act general
Classes_New Which of the following is correct for an abstract purpose
QB class. (Choose TWO) MCA methods
Inheritance_In
terfaces_Abstr
act class Vehicle {
Classes_New Which of the following defines a legal abstract abstract void
QB class? MCQ display(); }
Consider the code below & select the correct
ouput from the options:
class Mountain{
int height;
protected Mountain(int x) { height=x; }
public int getH(){return height;}}
class SomeException {
}
class A {
public void doSomething() { }
}
Inheritance_In
terfaces_Abstr class B extends A {
act public void doSomething() throws Compilation of
Classes_New SomeException { } both classes A
QB } MCQ & B will fail
No—if a class
implements
several
Inheritance_In interfaces,
terfaces_Abstr each constant
act Is it possible if a class definition implements two must be
Classes_New interfaces, each of which has the same defined in only
QB definition for the constant? MCQ one interface
Inheritance_In Private
terfaces_Abstr methods
act cannot be
Classes_New overridden in
QB Select the correct statement: MCQ subclasses
Holds the
location of
Core Java
Introduction_t Class Library
o_Java_and_ Which of the following statement gives the use (Bootstrap
SDE_NewQB of CLASSPATH? MCQ classes)
Packages can
Introduction_t contain only
o_Java_and_ Which of the following are true about Java Source
SDE_NewQB packages? (Choose 2) MCA files
Introduction_t
o_Java_and_ Which of the following options give the valid
SDE_NewQB argument types for main() method? (Choose 2) MCA String [][]args
Introduction_t
o_Java_and_ Which of the following options give the valid dollorpack.
SDE_NewQB package names? (Choose 3) MCA $pack.$$pack
Introduction_t
o_Java_and_ The term 'Java Platform' refers to Java Compiler
SDE_NewQB ________________. MCQ (Javac)
Using
forName()
JDBC_NewQ which is a
B how to register driver class in the memory? MCQ static method
Give Code snipet:
{// Somecode
ResultSet rs = st.executeQuery("SELECT *
FROM survey");
while (rs.next()) {
String name = rs.getString("name");
System.out.println(name);
}
rs.close();
// somecode
JDBC_NewQ } What should be imported related to java.sql.Resul
B ResultSet? MCQ tSet
JDBC_NewQ DriverManage
B getConnection() is method available in? MCQ r Class
Given :
public class MoreEndings {
public static void main(String[] args) throws
Exception {
Class driverClass =
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver
");
DriverManager.registerDriver((Driver)
driverClass.newInstance());
// Some code
JDBC_NewQ } Inorder to compile & execute this code, what
B should we import? MCQ java.sql.Driver
Which of the following method can be used to
JDBC_NewQ execute to execute all type of queries i.e. either
B Selection or Updation SQL Queries? MCQ executeAll()
class CreateFile{
public static void main(String[] args) {
try {
File directory = new File("c"); //Line 13
File file = new File(directory,"myFile");
if(!file.exists()) {
file.createNewFile(); //Line 16
}}
catch(IOException e) {
e.printStackTrace }
}}}
If the current direcory does not consists of Line 16 is
JDBC_NewQ directory "c", Which statements are true ? never
B (Choose TWO) MCA executed
1) Driver 2)
Connection 3)
ResultSet 4)
JDBC_NewQ Which of the following options contains only DriverManage
B JDBC interfaces? MCQ r 5) Class
Rodent rod;
Rat rat = new Rat();
Mouse mos = new Mouse();
Keywords_var PocketMouse pkt = new PocketMouse();
iables_operat
ors_datatypes Which one of the following will cause a compiler
_NewQB error? MCQ rod = mos
accessModifier returnType
methodName( parameterList )
{
Java statements
accessModifier returnType
methodName( parameterList )
{
Java statements
return returnValue;
Keywords_var }
iables_operat It must always
ors_datatypes be private or
_NewQB What is true for the accessModifier? MCQ public
class Test{
public static void main(String[] args){
byte b=(byte) (45 << 1);
Keywords_var b+=4;
iables_operat System.out.println(b); }}
ors_datatypes What should be the output for the code written
_NewQB above? MCQ 48
Keywords_var What is the value of y when the code below is
iables_operat executed?
ors_datatypes int a = 4;
_NewQB int b = (int)Math.ceil(a % 3 + a / 3.0); MCQ 1
Consider the following code and choose the
correct option:
class Test{
class A{
interface X{
int z=4; } }
Keywords_var static void display(){
iables_operat System.out.println(new A().X.z); }
ors_datatypes public static void main(String[] args) {
_NewQB display(); }} MCQ
Given
class MybitShift
{
public static void main(String [] args)
{
int a = 0x5000000;
System.out.print(a + " and ");
Keywords_var a = a >>> 25;
iables_operat System.out.println(a);
ors_datatypes } 83886080 and
_NewQB } MCQ -2
Consider the code below & select the correct
ouput from the options:
class C{
public static void main (String[] args) {
byte b1=33; //1
b1++; //2
byte b2=55; //3
b2=b1+1; //4
Keywords_var System.out.println(b1+""+b2);
iables_operat }}
ors_datatypes Consider the code above & select the correct compile time
_NewQB output. MCQ error at line 2
class Test{
public static void main(String[] args){
int var;
var = var +1;
Keywords_var System.out.println("var ="+var);
iables_operat }} compiles and
ors_datatypes consider the code above & select the proper runs with no
_NewQB output from the options. MCQ output
class Accounts
Keywords_var {
iables_operat public double calculateBonus(){//method's
ors_datatypes code}
_NewQB } MCQ Aggregation
Given classes A, B, and C, where B extends A,
Keywords_var and C extends B, and where all classes
iables_operat implement the instance method void doIt().
ors_datatypes How can the doIt() method in A be It is not
_NewQB called from an instance method in C? MCQ possible
Keywords_var
iables_operat
ors_datatypes Which of the following will declare an array and Array a = new
_NewQB initialize it with five numbers? MCQ Array(5);
Keywords_var
iables_operat
ors_datatypes Which of the following are correct variable
_NewQB names? (Choose TWO) MCA int #ss;
What is the output of the following:
int a = 0;
Keywords_var int b = 10;
iables_operat
ors_datatypes a = --b ;
_NewQB System.out.println("a: " + a + " b: " + b ); MCQ a: 9 b:11
int value = 0;
Keywords_var int count = 1;
iables_operat value = count++ ;
ors_datatypes System.out.println("value: "+ value + " count: " value: 0
_NewQB + count); MCQ count: 0
Extend
java.lang.Thre
ad and
Threads_New Which of the following statements can be used override the
QB to create a new Thread? (Choose TWO) MCA run() method.
Given:
public class Threads4 {
public static void main (String[] args) {
new Threads4().go();
}
public void go() {
Runnable r = new Runnable() {
public void run() {
System.out.print("run");
}
};
Thread t = new Thread(r);
t.start();
t.start();
}
Threads_New } Compilation
QB What is the result? MCQ fails.
class Thread2 {
public static void main(String[] args) {
new Thread2().go(); }
public void go(){
Runnable rn=new Runnable(){
public void run(){
System.out.println("Good Day.."); } };
Thread t=new Thread(rn);
t.start();
}}
Threads_New what should be the correct output for the code Compilation
QB written above? MCQ fails.
wait(2000);
After thread A
After calling this method, when will the thread A is notified, or
Threads_New become a candidate to get another turn at the after two
QB CPU? MCQ seconds.
Threads_New wait(), notify() and notifyAll() methods belong to
QB ________ MCQ Object class
if ( ring.startsWith("One") &&
find.startsWith("One") ) One ring to
strings_string System.out.println( ring+find ); rule them all,
_buffer_NewQ else One ring to
B System.out.println( "Different Starts" ); MCQ find them.
The code will
Consider the following code and choose the fail to compile
correct option: because the
class MyClass { expression
String str1="str1"; str3.concat(str
String str2 ="str2"; 1) will not
String str3="str3"; result in a
str1.concat(str2); valid
strings_string System.out.println(str3.concat(str1)); argument for
_buffer_NewQ } the println()
B } MCQ method
Given:
public class Theory {
public static void main(String[] args) {
String s1 = "abc";
String s2 = s1;
s1 += "d";
System.out.println(s1 + " " + s2 + " " +
(s1==s2));
class StringManipulation{
public static void main(String[] args){
String str = new String("Cognizant");
str.concat(" Technology");
StringBuffer sbf = new StringBuffer("
Solutions");
System.out.println(str+sbf);
strings_string }} Cognizant
_buffer_NewQ consider the code above & select the proper Technology
B output from the options. MCQ Solutions
EqTest(){
String s="Java";
String s2="java";
// Line X
{
System.out.println("Equal");
}else
{
System.out.println("Not equal");
strings_string }
_buffer_NewQ }
B } MCQ if(s==s2)
import java.io.*;
public class MyClass implements Serializable {
private int a;
public int getA() { return a; }
publicMyClass(int a){this.a=a; }
private void writeObject( ObjectOutputStream
s)
throws IOException {
// insert code here
}
}
FileOutputStre
am fos = new
Which of the following opens the file FileOutputStre
IO_Operation "myData.stuff" for output first deleting any file am( "myData.
s_NewQB with that name? MCQ stuff", true )
import java.io.*;
public class MyClass implements Serializable {
Given :
import java.io.*;
public class ReadingFor {
public static void main(String[] args) {
String s;
try {
FileReader fr = new FileReader("myfile.txt");
BufferedReader br = new BufferedReader(fr);
while((s = br.readLine()) != null)
System.out.println(s);
br.flush();
} catch (IOException e) { System.out.println("io
error"); }
}
}
And given that myfile.txt contains the following
two lines of data:
ab
IO_Operation cd
s_NewQB What is the result? MCQ ab
throws a
IO_Operation What happens when the constructor for DataFormatEx
s_NewQB FileInputStream fails to open a file for reading? MCQ ception
A compilation
error will
occur at (Line
A compilation no 2), since
error will the class does
occur at (2), not have a
since the constructor
class does not that takes one The program
have a default argument of will compile
constructor type int. without errors. 0 0 0
The compiler
The code will will complain
compile but that the
The compiler complain at method
will complain run time that myfunc in the
that the Base the Base base class
class has non class has non has no body,
abstract abstract nobody at all
methods methods to print it 1 0 0
The
returnValue
must be the
same type as
the
returnType, or The
If the be of a type returnValue
returnType is that can be must be
void then the converted to exactly the
returnValue returnType same type as
can be any without loss of the
type information returnType. 0 0 1
Compiles but
throws
Comiples and runtime Compiles and
prints From A exception display 3 0 1 0
1 2 100 100 10 20 1 2 100 1 2 10 20 100
10 20 100 100 0 0 0
Compiles but
Compiles and doesn't
throw run time display Compilation
exception anything fails 1 0 0
code compiles
but will not compliation j can not be
display output error initialized 0 0 1
Only A is
All are TRUE All are FALSE TRUE 0 0 0
An exception
Compilation is thrown at
Short Long fails. runtime. 1 0 0
Compiles and
throws run Compilation Compiles and
time exception fails displays Hi 0 0 1
compiles
successfully
but runtime
error compile error none of these 0 0 1
Compiles and
runs without Compiles and Compiles and
any output display 2 display 0 0 0 1
0,0 compile error runtime error 1 0 0
It is not
possible to
access a
static variable
Compilation Garbage in side of non
Error Value static method 1 0 0
default zero
default default zero one two 0 0 1
The program
The compiler will compile
will find the The program successfully,
error and will will compile but the .class
not make a and run file will not run
.class file successfully correctly 0 1 0
1 2 3 0 0 0
Cat Ant Dog Dog Man Cat
Man Ant compile error 0 0 1
Compilation
Error occurs
and to avoid
A Sequence them we need
of 5 one's will to declare
be printed like IndexOutOfBo Mine class as
11111 undes Error abstract 0 0 0
Compiler
Error: size of
array must be
2 1 defined 0 1 0
false 0 1
Runtime
Exception 2500 50 0 0 1
It is not
possible to
declare a
static variable
in side of non
static method
or instance
method.
Because
Static
Compile time variables are
error because Compilation class level
i has not been and output of dependencies
initialized null . 0 0 0
Unresolved
compilation
problem: The
local variable
i1 may not Compilation
have been and output of None of the
initialized null given options 0 1 0
Compiles and
runs without Compiles and Compilation
any output display 0 error 0 0 0
CONSTRUCT
METHOD RUNTIME OR CLASS 0.333333 0 0.333333
Compile time
and
Information for deploytime Runtime Information for
the JVM processing processing the OS 0.333333 0 0.333333
false 0 1
all the listed
@inherit @include options 1 0 0
Compilation Compilation
The code runs An exception fails because fails because
with no is thrown at of an error in of an error in
output. runtime line 21 line 23. 1 0 0
An exception
Compilation is thrown at
B, C, A, fails. runtime. 0 1 0
The before()
method will
The before() throw an The before()
method will exception at method will
print 1 2 3 runtime not compile 0 0 1
none of the
-1 listed options 0 1 0
2 3 4 0 0 1
Compiles but
exception at
prints 3,4,2,1, prints 1,2,3,4 runtime 0 0 1
tSetdelete(ne tSet.remove(n
w ew tSet.drop(new
Integer("1")); Integer("1")); Integer("1")); 0 0 1
3 -5 2 -6 3 -4 0 0 1
{4=Four, {2=Two,
6=Six, {4=Four, 4=Four,
7=Seven} 6=Six} 6=Six} 0 0 1
none of the
-1 null listed options 0 0 1
2 3 4 0 0 0
Compilation
000120 00012021 error 0 1 0
Compilation
harrier fails. collie harrier 0 0 0
compilation
false error Compiles 0 1 0
NumberForma
2.147483648 tException at Compiles but
E9 run time no output 0 0 1
Compilation
shepherd retriever fails. 0 0 0
21 22 23 24 0 0 1
24 234 246 0 1 0
Compiles but
Three Five no output 1 0 0
82 91 92 0 1 0
If a is false If a is false
If a is true and and b is false and b is true
b is true then then the then the
the output is output is output is
"A && B" "ELSE" "ELSE" 0 0 0
Compilation
28 Error 10 Runtime Error 0 0 1
There are There are
syntax errors syntax errors There is a
on lines 1 and on lines 1, 6, syntax error
6 and 8 on line 6 0 0 0
Compilation
s++; s = s + s * i; s *= i; error 0 0 0
Compilation
hi world world world fails. 0 0 0
Compiles but
compilation error at run
46 error time 1 0 0
b= b= b=
nf.format( inpu nf.equals( inp nf.parseObjec
t ); ut ); t( input ); 0 1 0
Compiles but
Compilation error at run None of the
error time listed options 0 1 0
No, Runtime
error Yes, 10, 100 Yes, 100, 100 0 0 0
true false 1 0 0 1
2 4 1 0 0 0
good morning
morning …. compiler error runtime error 0 0 1
Compilation bat man
error spider man spider man 0 0 1
Compilation
32 25 Error Runtine Error 0 0 1
3 23 123 0 0 1
ArrayList is a LinkedList is a Stack is a
sub class of subclass of subclass of
Vector ArrayList Vector 0.5 0 0
[608, 610,
[608, 610, An exception 612, 629]
612, 629] is thrown at [608, 610,
[608, 610] runtime. 629] 0 0 1
default compilation
brownie error default 1 0 0
5 7 9 11 0 0 0
An exception pi is bigger
pi is bigger occurs at than 3. Have
than 3. runtime. a nice day. 1 0 0
Compilation Compilation
012122 fails at line 11 fails at line 12. 0 0 1
Compiles but
Compilation error at run None of the
error time listed options 0 1 0
Compilation
j=0 j=1 fails 0 0 0
Person p[][] =
new Person[2]
Person p[5]; Person[] p []; []; 0 1 0
Compiles but
Compilation error at run
error time 0 null 0 0 1
Changes
made in the
Set view
returned by The Map
keySet() will interface All Map
be reflected in extends the All keys in a implementatio
the original Collection map are ns keep the
map interface unique keys sorted 0 0.5 0
M.S.Dhoni
Sachin Virat
Kohli Virat Kohli all of these 1 0 0
If a variable of
type int
overflows
during the
An overflow execution of a
error can only A loop may loop, it will
occur in a have multiple cause an
loop exit points exception 0 0 1
A run time
error
indicating that Clean compile
no run method and at run
is defined for time the Clean compile
the Thread values 0 to 9 but no output
class are printed out at runtime 0 0 0
An exception
is thrown at
Not true runtime. none 1 0 0
true 0 1
Cannot
Compilation determine prints 12 12
Error output. 12 12 0 0 0
A try block
cannot be A finally block
followed by must always
both a catch An empty A catch block follow one or
and a finally catch block is cannot follow more catch
block not allowed a finally block blocks 0 0 0
A method
declaring that
it throws a
An overriding certain
method must exception Finally blocks
declare that it The main() class may are executed
throws the method of a throw if,an exception
same program can instances of gets thrown
exception declare that it any subclass while inside
classes as the throws of that the
method it checked exception corresponding
overrides exception class try block 0 0 0.5
2, 3, 4 and 5 1, 4, 5 and 6 2, 4, 5 and 6 0 0 1
X run = new
Thread t = X(); Thread t =
new new Thread t =
Thread(X); Thread(run); new Thread();
t.start(); t.start(); x.run(); 0 0 1
No output,
and an X, followed by
Exception is an Exception,
thrown. followed by B. none 1 0 0
compilation ArithmeticExc
Exception fails eption 0 0 1
static methods
can be called static methods
using an do not have
object direct access
reference to static methods to non-static
an object of are always methods
the class in public, which are
which this because they defined inside
method is are defined at the same
defined. class-level. class. 0 0.5 0
exit
RuntimeExce
ption thrown Compilation
exit at run time fails 0 0 1
Exception
occurred
RuntimeExce RuntimeExce does not
ption ption compile 0 0 0
2, 4, 5 1, 2, 6 2, 3, 4 0 0 1
We cannot
have a try
We cannot block block
have a try without a
block without catch / finally Nothing is
a catch block block diaplayed 0 0 1
An exception
Compilation is thrown at
meow fails runtime. peep 0 0 0
Thread t =
Thread t = Thread t = new
new new Thread(); Thread(X);
Thread(X); x.run(); t.start(); 1 0 0
Variables can
be protected
If a class has from
synchronized concurrent
code, multiple access
threads can problems by
still access marking them When a
the with the thread sleeps,
nonsynchroniz synchronized it releases its
ed code. keyword. locks 0 1 0
Compiles but
Compiles and Compilation exception at
no output fails runtime 0 0 1
throws
throws throw RuntimeExce
Exception Exception ption 0 1 0
Implement Extend
Extend java.lang.Thre java.lang.Run Implement
java.lang.Thre ad and nable and java.lang.Thre
ad and implement the override the ad and
override the start() start() implement the
run() method. method. method. run() method. 0.5 0.5 0
Arithmetic
Exception
Runtime Runtime compilation
Exception Exception error 1 0 0
Compilation finally
fails. exception finally 0 0 1
Compilation Compilation Compilation
5 followed by fails with an fails with an fails with an
an exception error on line 7 error on line 8 error on line 9 0 0 0
Code output:
Code output: Code output: Start Hello
Start Hello Start Hello world Catch
world File Not world End of Here File not
Found file exception. found. 1 0 0
Any statement
Any statement that can throw
The Error that can throw an Exception
class is a an Error must must be
RuntimeExce be enclosed in enclosed in a
ption. a try block. try block. 1 0 0
does not none of the
compile runtime error listed options 0 0 1
hello throwit
RuntimeExce hello throwit
Compilation ption caught caught finally
fails after after 0 0 0
NumberForma
tException ParseExceptio
thrown at Compilation n thrown at
runtime fails runtime 0 0 1
A A
ParseExceptio NumberForma
n is thrown by tException is
the parse thrown by the
Compilation method at parse method
fails runtime. at runtime. 0 1 0
Compilation Compilation
fails because fails because
of an error in of an error in
A,B,Exception line 20. line 14. 0 0 0
The notify()
The notify() method
method is causes a
To call sleep(), defined in thread to
a thread must class immediately
own the lock java.lang.Thre release its
on the object ad locks. 1 0 0
End of End of
run method. method. run.
java.lang.Runt java.lang.Runt java.lang.Runt
imeException: imeException: imeException:
Problem Problem Problem 0 0 0
Unchecked
exceptions Exception all of these 0 1 0
Compiles but
Compilation error at run
error time 0 0 1
Declaring the
Synchronizing doThings()
the run() method as
method would static would
make the make the An exception
class thread- class thread- is thrown at
safe. safe. runtime. 0 0 1
Compiles but
Compilation exception at
exit fails runtime 0 0 0
An object will
not be
garbage
collected as
The finalize() long as it
The finilize() method will possible for a The garbage
method will never be live thread to collector will
eventually be called more access it use a mark
called on than once on through a and sweep
every object an object reference. algorithm 0 0 0.5
B C D 0 0 1
Only the
garbage
collection
system can
Runtime.getR destroy an
x.finalize() untime().gc() object. 0 0 0
1 2 3 0 0 1
none of the
Thi is java This i java Thi i java listed options 0 0 0
Call
System.gc()
passing in a
reference to Garbage
the object to collection
be garbage Call Call cannot be
collected System.gc() Runtime.gc(). forced 0 0 0
1 2 3 0 1 0
Create an
Compile time object for
error Interface only Runtime Error 0 1 0
This is a final
method Some Compilation illegal Some
error message error error message 0 0 1
B C D 0 0 0
Compilation
4, 5 5, 4 fails 0 0 0
Compilation
47 7 0 error 47 47 47 0 0 0
A a2=(B)c; C c2=(C)(B)c; A a1=(Test)c; 0 0 0
Compiles but
Compilation error at
error sum of int7 runtime 0 0 1
Compiles but
Compilation error at run Runs but no
error time output 0 1 0
Compiles but
Compilation error at run
error time 9 0 1 0
No—a Yes—the
variable must variable can
always be an refer to any
object No—a object whose
reference type variable must class
or a primitive always be a implements
type primitive type the interface 0 0 0
Compiles but
compilation error at
4 error runtime 0 0 1
The statement The statement
The statement a.j = 5; is The statement b.i = 3; is
b.f(); is legal legal. a.g(); is legal legal. 0.333333 0.333333 0
final double
circumference protected int
= 2 * Math.PI CODE = int AREA = r * public static
* r; 31337; s; MAIN = 15; 0 0.5 0
compile time
error hello hellohello 0 1 0
Compiles but
Compilation error at run
error time null 0 1 0
we must use
always
implements
and later we we can use in extends and
must use any order its implements
extends not at all a can't be used
keyword. problem together 1 0 0
Compilation
s 16 s 10 fails. 0 0 0
If you define D If you define D
e = (D) (new e = (D) (new
E()), then E()), then
e.methodB() e.methodB()
invokes the invokes the
version of Compilation version of
methodB() fails, due to methodB()
defined at line an error in line defined at line
9 7 5 0 1 0
It must be It must be
used in the used in the
Only one child last statement first statement
class can use of the of the
it constructor. constructor. 0 0 0
Compiles but
Compilation error at run Runs but no
error time output 0 1 0
Compiles but
Compilation error at
error Hello B runtime 0 0 0
Definitely
legal at Definitely
Legal at runtime, but legal at
compile time, the cast runtime, and
but might be operator (Sub) the cast
illegal at is not strictly operator (Sub)
runtime needed. is needed. 0 1 0
p1 =
p2 = p4; (ClassB)p3; p1 = p2; 0.5 0 0.5
Compiles but
Compilation error at
error 90 mph runtime 1 0 0
Compiles but
Compilation error at
error Hello B runtime 0 0 1
Because of
single Because of Because of
inheritance, single single
Mammal can inheritance, inheritance,
have no other Animal can Mammal can
parent than have only one have no
Animal subclass siblings. 0 1 0
100 followed
200 by 200 100 0 0 1
compile error runtime error none 0 1 0
The statement
a.j = 5; is The statement The statement
legal. b.f(); is legal. a.g(); is legal. 0.333333 0 0.333333
cannot call
by creating an because it is
instance of overridden in
this keyword the base class derived class 1 0 0
Compiles but
error at run
time 90 mph 150 mph 1 0 0
A
The code runs NullPointerEx
Cannot add with no ception is
Toppings output. thrown 1 0 0
Compiles but
Compilation error at run Runs but no
error time output 0 1 0
No—but a
object of Yes—an
parent type object can be Yes—any
can be assigned to a object can be
assigned to a reference assigned to
variable of variable of the any reference
child type. parent type. variable. 0 0 1
If both a If neither
subclass and super() nor
its superclass this() is Calling
do not have declared as super() as the
any declared the first If super() is first statement
constructors, statement in the first in the body of
the implicit the body of a statement in a constructor
default constructor, the body of a of a subclass
constructor of this() will constructor, will always
the subclass implicitly be this() can be work, since all
will call inserted as declared as superclasses
super() when the first the second have a default
run statement. statement constructor. 0 1 0
Compiles but
Compilation error at
error Fun Run runtime 0 0 1
Compiles but
Compilation error at run Runs but no
error time output 0 1 0
An abstract
class is one
which
contains some
defined An abstract
methods and class is one
some which Abstract class
undefined contains only can be
methods static methods declared final 0.5 0.5 0
abstract class
Vehicle
abstract class abstract { abstract void abstract class
Vehicle Vehicle display(); Vehicle
{ abstract void { abstract void { System.out.p { abstract void
display(); } display(); } rintln("Car"); }} display(); } 0 0 0
Compiles but
Compilation error at run Compiles but
error time no output 1 0 0
Compilation of Compilation of
class A will class B will
fail. fail.
Compilation of Compilation of Compilation of
both classes class B will class A will
will succeed succeed succeed 0 0 0
Yes— either
of the two
variables can
No—a class be accessed Yes—since
may not through : the definitions
implement interfaceNam are the same
more than one e.variableNam it will not
interface e matter 0 0 1
An overriding The
method can parameter list
declare that it of an
throws overriding
checked method can The overriding
exceptions be a subset of method must
A subclass that are not the parameter have different
can override thrown by the list of the return type as
any method in method it is method that it the overridden
a superclass overriding is overriding method 1 0 0
Compiles but
Compilation error at
error Hello B runtime 0 1 0
Helps the
compiler to
find the
source file
that
corresponds
to a class, Helps
when it does Helps JVM to Javadoc to
not find a find and build the Java
class file while execute the Documentatio
compiling classes n easily 0 1 0
Holds the
Holds the location of
location of User Defined
Java classes, Holds the
Extension packages and location of
Library JARs Java Software 0 0 1
Class and
Interfaces in
the sub
packages will
be
Sub packages automatically
Packages can Packages can should be available to
contain both contain non- declared as the outer
Classes and java elements private in packages
Interfaces such as order to deny without using
(Compiled images, xml importing import
Classes) files etc. them statement. 0 0.5 0.5
Object class
Object class provides the
has the core method for Object class
Object class methods for Set implements
cannot be thread implementatio Serializable
instantiated synchronizatio n in Collection interface
directly n framework internally 0 0 0.5
Java
Java Runtime Database
Environment Connectivity Java
(JRE) (JDBC) Debugger 0 1 0
registerDriver(
) method and
Class.forNam Class.forNam
e() e() getConnection 0 0 1
Using the
static method
registerDriver(
) method
which is Either
available in forName() or
DriverManage registerDriver( None of the
r Class. ) given options 0 0 1
java.sql.Driver java.sql.Conn
java.sql.Driver Manager ection 1 0 0
Compiles but
Compilation error at run Compiles but
error time no output 0 0 1
ResultSetMet DatabaseMet Database.get
aData.getMax aData.getMax MaxConnectio
Connections Connections ns 0 0 1
false 1 0
java.sql.Driver
java.sql.Driver java.sql.DataS
java.sql.Driver Manager ource 0 0 1
executeQuery
executeSQL() execute() () 0 0 1
Compiles but
Compilation error at run
error will show city time 0 0 0
false 1 0
Read only, Updatable,
Updatable, Scroll Scroll
Forward only Sensitive sensitive 1 0 0
false 1 0
CallableState PreparedState
ment ment RowSet 0 0 1
Line 13
creates a
Line 13 directory
An exception creates a File named “c” in
is thrown at object named the file
runtime “c” system. 0 0.5 0.5
1) Driver 2)
Connection 3)
ResultSet 4) 1) Driver 2)
ResultSetMet Connection 3)
aData 5) ResultSet 4)
Statement 6) ResultSetMet
DriverManage aData 5)
r 7) Statement 6)
PreparedState PreparedState
ment 8) ment 7)
Callablestate Callablestate
ment 9) ment 8)
DataBaseMet DataBaseMet All of the
aData aData given options 0 0 1
13 2 3 1 0 0
Compiles but
error at run Compilation
282 time error 0 1 0
pkt = rat pkt = null rod = rat 0 1 0
A A
ParseExceptio NumberForma
n is thrown by tException is
the parse thrown by the
Compilation method at parse method
error runtime at runtime 0 1 0
Compilation
t9 a9 error 1 0 0
An exception
is thrown at
23 000 runtime 0 0 0
The The
returnValue returnValue
can be any must be the
type, but will same type as
be the
automatically returnType, or
converted to If the be of a type
returnType returnType is that can be
when the void then the converted to
method returnValue returnType
returns to the can be any without loss of
caller. type information. 0 0 0
Compiles but
Compilation error at run
error time 0 1 0
Line 1, Line 3,
Line 5 Line 1, Line 5 Line 4 Line 5 0 0 0
Compiles but
Compilation error at run
error time 1 0 0
Compilation
13.5 13 Error Runtime Error 0 0 0
sum = sum +
1; value = value = value value = value
value + sum; + sum; + ++sum; 1 0 0
19 follwed by Compile time 10 followed by
20 error 1 1 0 0
x = 3, y = 2, z x = 4, y = 1, z x = 4, y = 2, z
=6 =5 =6 0 1 0
It can be
omitted, but if
not omitted
there are It can be
several The access omitted, but if
choices, modifier must not omitted it
including agree with the must be
private and type of the private or
public return value public 0 1 0
An exception
is thrown at
args[2] = 3 args[2] = null runtime 0 0 0
11, 1 10, 0 11 , 0 0 1 0
Compiles but
error at run Compilation
94 time error 0 1 0
2 3 4 0 0 1
Compiles but
Compilation error at run
error time 4 0 1 0
compilation
0 6 1 7 2 8 3 9 0 5 1 5 2 5 3 5 fails 1 0 0
An exception
Compilation is thrown at
9, 8, 7, 6, 5, fails runtime 0 0 1
B C D 0 0 0
Compiles but Compiles but
Compilation error at run run without
error time output 1 0 0
does not
var = 1 compile run time error 0 0 1
Simple
Association Dependency Composition 0 0 1
his.super.doIt( ((A)
super.doIt() ) this).doIt(); A.this.doIt() 1 0 0
int [] a =
{23,22,21,20,1 int a [] = new
9}; int[5]; int [5] array; 0 1 0
4 random value 1 0 0
11, 1 10, 0 11 , 0 0 0 0
A sequence of
Garbage
Values are compile time Compiles but
printed Error no output 0 0 1
will print Hi
twice and
throws
will print Hi exception at
Once will not print runtime 0 0 0
Extend Implement
java.lang.Run Implement Implement java.lang.Thre
nable and java.lang.Thre java.lang.Run ad and
override the ad and nable and implement the
start() implement the implement the start()
method. run() method. run() method method. 0.5 0 0
Compiles but
throws run
compilation time a1 is not a
error Exception Thread 0 0 0
The code
The code executes
An exception executes normally, but
is thrown at normally and nothing is
runtime. prints "run". printed. 0 1 0
The code
executes
An exception normally and
is thrown at prints "Good prints Good
runtime. Day.." Day.. Twice 0 0 1
new
new new Thread(new
Thread(MyRu MyRunnable() MyRunnable()
nnable).run(); .start(); ).start(); 0 0 0
Compilation
hi world world error 0 0 0
Compilation
2 6 error 1 0 0
Compilation
1 4 fails. 0 0 0
Compiles but
Compilation exception at
abc78 error run time 0 0 1
true 1 0 1 0
result =
result.concat( concat(String
stringA, result+stringA A).concat(Stri
stringB, +stringB+strin ngB).concat(S
stringC ); gC; tringC) 1 0 0
A R I 0 0 1
Compilation Compilation
and output the and output the Compile time
string "ello" string elloH error 0 0 0
Compilation
6 error 1 0 0
Compilation
at atm error 0 1 0
27 24 11 0 1 0
result =
result.concat( concat(String
stringA, result+stringA A).concat(Stri
stringB, +stringB+strin ngB).concat(S
stringC ); gC; tringC) 1 0 0
Compilation
hi world world error 1 0 0
Compilation
204 205 error 0 1 0
Compiles but
exception at Compilation
run time 788232 error 0 0 1
FileOutputStre
DataOutputStr am fos = new
FileOutputStre eam dos = FileOutputStre
am fos = new new am( new
FileOutputStre DataOutputStr BufferedOutp
am( "myData. eam( "myData utStream( "my
stuff") .stuff" ) Data.stuff") ) 0 1 0
A instance of
MyClass and
An exception An instance of an instance of
is thrown at MyClass is Tree are both
runtime serialized serialized 1 0 0
the state of
the object s1
Compiles but will not be
Compilation error at run store to the
error time file. 1 0 0
reads data
from file
named jlist.lst
in byte form Compiles but
Compilation and ascii error at
error value runtime 0 0 1
reads data
from file
named jlist.lst
in byte form Compiles but
Compilation and display error at
error garbage value runtime 1 0 0
Compiles and
Compiles but executes but
Compilation error at run directory is
error time not created 1 0 0
writes data to
the file in Compiles but
Compilation character error at
error form. runtime 1 0 0
Compilation
abcd ab cd abcd Error 0 0 0
the state of
the object s1
Compiles but will not be
Compilation error at run store to the
error time file. 0 0 1
reads data
from file
named jlist.lst
in byte form Compiles but
Compilation and display error at
error garbage value runtime 0 1 0
reads data
from file
named jlist.lst
in byte form Compiles but
Compilation and display error at
error garbage value runtime 1 0 0
throws a
throws a ArrayIndexOut
FileNotFound OfBoundsExc
Exception eption returns null 0 1 0
Compiles and
Compiles but executes but
Compilation error at run directories are
error time not created 0 0 0
I am a Person I am a
I am a I am a Student I am
Student Student a Person 0 1 0
B,C C,D A,B 0 0 0
The file
The file system has a
The file system has a directory
system has a directory named
new empty named dir, newDir,
directory containing a containing a Compilation
named newDir file f1.txt file f1.txt error 0 0 0
Compiles and
runs but
Compiles but content not
Compilation error at transferred to
error runtime the temp.txt 0 0 0
The program
The program will compile,
The program will compile print H|e|l|l|o|,
will compile and print H|e|l| and then
and print H|e|l| l|o|End of terminate
l|o|Input error. stream. normally. 0 0 0
The file is
modified from
The boolean The boolean being
value false is value true is unwritable to none of the
returned returned being writable. listed options 0 1 0
void add(int void add(int
char add(float x,int y) char x,int y) void
x) char add(char sum(double
add(float y) x,char y) x,double y) 0 0 1
avoiding
method name
Code flexibility confusion at
Code reuse at runtime runtime 0 0 1
Microprocess
or - Computer Tea -Cup Driver -Car 1 0 0
0.5
0
0
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0 0.33
1
0
0
0
1
0
0
0
1
0
0
1
0
0
0.333333 0.333333
0 0.333333
0.333333 0
0 0
0
0
0
1 0
0
0
1
0
0
0
0 0
0
0 0
0
0
1
0
0
0
0 0
0
0
0
1
0 0
1
1 0
0.5 0
1
0
1
0
1
0
1 0
0
0
0 0
0
0.5
0
0 1
0
0
0
0
0 0
0
0
0
0
0
0.5 0
1 0
0
0
0 0.25
0 0.33
1
0
0
1
1 0
0.5 0
0
0
0
0.5
0.5
0
1
0.5
0
1 0
1 0
0
0
0 0
0
0.5 0.5
0
0
0
0
0 0.5
1
0
0
0
0.5 0
0
1
1 0
0 1
0
0
0
1
1
1
1
1
0
0
1
0
0.333333 0
0.5 0
0
0
1
0
1
0
0
0
0
0
0.333333
0
0
0 0.25
0
0 0
0
0
0 1
0
0
0 0
0
0 0
0.5 0.5
0 0
0.5 0
0
0
0 0
1
0
0 0
0
0
0
0
0.333333 0
0
0
0
1
1 0
1
0
0 1
1 0
0
0
1
0
0
0
1
1
0 0
1
0
0 0
0.5
0
0
0
0.5 0
0
0.5 0
0
0
0
0
1
0
0
1 0
0 0.5
0
0
1
0
0
0
0 0
0
0
0
0
0
0 1
0
0
0
1
1 0
1
1
0 0
0