CJ MCQ
CJ MCQ
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()"); Meal() Meal() Cheese()
} Meal() Cheese() Lunch() Sandwich()
} Lunch() Lunch() PortableLunc Meal()
public class MyClass7 { PortableLunc PortableLunc h() Lunch()
public static void main(String[] args) { h() Cheese() h() Sandwich() PortableLunc
new Sandwich(); Sandwich() Sandwich() Cheese() h()
36 Consider the following code and choose the
correct option:
class A{ int a; A(int a){a=4;}}
class B extends A{ B(){super(3);} void
displayA(){
System.out.print(a);}
public static void main(String args[]){ compiles and compilation Compiles and Compiles and
new B().displayA();}} display 0 error display 4 display 3
37
Given the following code what will be output?
public class Pass{
static int j=20;
public static void main(String argv[]){
int i=10;
Pass p = new Pass();
p.amethod(i);
System.out.println(i);
System.out.println(j);
}
Error:
public void amethod(int x){ amethod
x=x*2; parameter
j=j*2; does not
} match
} variable 20 and 40 10 and 40 10, and 20
38 The compiler
will
automatically The program
change the The compiler will compile
What will happen if a main() method of a private will find the The program successfully,
"testing" class tries to access a private variable to a error and will will compile but the .class
instance variable of an object using dot public not make a and run file will not
notation? variable .class file successfully run correctly
39 11. class Mud {
12. // insert code here
13. System.out.println("hi");
14. }
15. }
And the following five fragments:
public static void main(String...a) {
public static void main(String.* a) {
public static void main(String... a) {
public static void main(String[]... a) {
public static void main(String...[] a) {
How many of the code fragments, inserted
independently at line 12, compile? 0 1 2 3
40 class Order{
Order(){
System.out.println("Cat");
}
public static void main(String... Args){
Order obj = new Order();
System.out.println("Ant");
}
static{
System.out.println("Dog");
}
{
System.out.println("Man");
}}
consider the code above & select the proper Man Dog Cat Cat Ant Dog Dog Man Cat
output from the options. Ant Man Ant compile error
41 abstract class MineBase {
abstract void amethod();
static int i;
} Compilation
public class Mine extends MineBase { Error occurs
public static void main(String argv[]){ and to avoid
int[] ar=new int[5]; them we
for(i=0;i < ar.length;i++) A Sequence A Sequence need to
System.out.println(ar[i]); of 5 zero's of 5 one's will declare Mine
} will be printed be printed IndexOutOfB class as
} like 0 0 0 0 0 like 1 1 1 1 1 oundes Error abstract
42 public class Q {
public static void main(String argv[]) { Compiler
int anar[] = new int[] { 1, 2, 3 }; Error: anar is Compiler
System.out.println(anar[1]); referenced Error: size of
} before it is array must be
} initialized 2 1 defined
43 A constructor may return value including class
type true false
44 Consider the following code and choose the
correct option:
package aj; class S{ int roll =23;
private S(){} }
package aj; class T
{ public static void main(String ar[]){ Compilation Compiles and Compiles and Compiles but
System.out.print(new S().roll);}} error display 0 display 23 no output
45 public class c123 {
private c123() {
System.out.println("Hellow");
}
public static void main(String args[]) {
c123 o1 = new c123();
c213 o2 = new c213();
}
}
class c213 {
private c213() {
System.out.println("Hello123"); It is not
} possible to
} declare a
constructor Compilation Runs without
What is the output? Hellow as private Error any output
46 class MyClass1
{
private int area(int side)
{
return(side * side);
}
public static void main(String args[ ])
{
MyClass1 MC = new MyClass1( );
int area = MC.area(50);
System.out.println(area);
}
} Compilation Runtime
What would be the output? error Exception 2500 50
47
It is not
possible to
declare a
public class MyAr { static variable
public static void main(String argv[]) { in side of non
MyAr m = new MyAr(); static method
m.amethod(); or instance
} method.
public void amethod() { Because
static int i1; Compile time Static
System.out.println(i1); error variables are
} because i Compilation class level
} has not been and output of dependencie
What is the Output of the Program? 0 initialized null s.
48 public class MyAr {
public static void main(String argv[]) {
MyAr m = new MyAr();
m.amethod();
} Unresolved
public void amethod() { compilation
final int i1; problem: The
System.out.println(i1); local variable
} i1 may not Compilation
} have been and output of None of the
What is the Output of the Program? 0 initialized null given options
49 public class c1 {
private c1()
{
System.out.println("Hello");
}
public static void main(String args[])
{
c1 o1=new c1(); It is not Can't create
} possible to object
} declare a because
constructor Compilation constructor is
What is the output? Hello private Error private
50 Which modifier indicates that the variable
might be modified asynchronously, so that all
threads will get the correct value of the
variable. synchronized volatile transient default
51
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;
System.out.println(set.equals(set2));
} Compile time Runtime
} What is the result of given code? true false error Exception
76 A)Property files help to decrease coupling
B) DateFormat class allows you to format
dates and times with customized styles.
C) Calendar class allows to perform date
calculation and conversion of dates and times
between timezones. A and B is A and D is A and C is B and D is
D) Vector class is not synchronized TRUE TRUE TRUE TRUE
77 Which interface does java.util.Hashtable Java.util.Tabl Java.util.Coll
implement? Java.util.Map Java.util.List e ection
78 Object get(Object key) - What does this
method return if the key is not found in the none of the
Map? 0 -1 null listed options
79 Consider the following code and choose the
correct option:
class Test{
public static void main(String args[]){
TreeSet<Integer> ts=new
TreeSet<Integer>();
ts.add(1);
ts.add(8);
ts.add(6);
ts.add(4);
SortedSet<Integer> ss=ts.subSet(2, 10);
ss.add(9);
System.out.println(ts);
System.out.println(ss); [1,4,6,8] [1,8,6,4] [1,4,6,8,9] [1,4,6,8,9]
}} [4,6,8,9] [8,6,4,9] [4,6,8,9] [4,6,8]
80 A) Iterator does not allow to insert elements
during traversal
B) Iterator allows bidirectional navigation.
C) ListIterator allows insertion of elements
during traversal
D) ListIterator does not support bidirectional A and B is A and D is A and C is B and D is
navigation TRUE TRUE TRUE TRUE
81 static void sort(List list) method is part of Collection Collections ArrayList
________ interface class Vector class class
82 static int binarySearch(List list, Object key) is ArrayList Collection Collections
a method of __________ Vector class class interface class
83 Which collection class allows you to access
its elements by associating a key with an
element's value, and provides java.util.Sorte java.util.Tree java.util.Tree java.util.Hash
synchronization? dMap Map Set table
84
Consider the following code and select the
correct output:
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class Lists {
public static void main(String[] args) {
List<String> list=new ArrayList<String>();
list.add("1");
list.add("2");
list.add(1, "3");
List<String> list2=new LinkedList<String>(list);
list.addAll(list2);
list2 =list.subList(2,5);
list2.clear();
System.out.println(list);
}
} [1,3,2] [1,3,3,2] [1,3,2,1,3,2] [3,1,2]
85 Given:
import java.util.*;
1) TreeSet
2) HashMap
3) LinkedList
4) an array 1 2 3 4
91 What will be the output of following code?
class Test{
public static void main(String args[]){
TreeSet<Integer> ts=new
TreeSet<Integer>();
ts.add(2);
ts.add(3);
ts.add(7);
ts.add(5);
SortedSet<Integer> ss=ts.subSet(1,7);
ss.add(4);
ss.add(6);
System.out.print(ss);}} [2,3,7,5] [2,3,7,5,4,6] [2,3,4,5,6,7] [2,3,4,5,6]
92
Consider the following code and choose the
correct option:
class Data{ Integer data; Data(Integer
d){data=d;}
public boolean equals(Object o){return true;}
public int hasCode(){return 1;}}
class Test{
public static void main(String ar[]){
Set<Data> s=new HashSet<Data>();
s.add(new Data(4));
s.add(new Data(2));
s.add(new Data(4));
s.add(new Data(1)); Compiles but
s.add(new Data(2)); compilation error at run
System.out.print(s.size());}} 3 5 error time
93 Consider the code below & select the correct
ouput from the options:
public class Test{
public static void main(String[] args) {
String num="";
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;
num=num+x+y; 0 0 0 1 2 0 2 Compilation
}System.out.println(num);}} 0001 000120 1 error
94 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 ");
case harrier:
System.out.print("harrier ");
}
}
} Compilation
What is the result? collie harrier fails. collie harrier
95 Consider the following code and choose the
correct output:
class Test{
public static void main(String args[]){
boolean flag=true;
if(flag=false){
System.out.print("TRUE");}else{ compilation
System.out.print("FALSE");}}} true false error Compiles
96 Cosider the following code and choose the
correct option:
class Test{
public static void main(String args[]){
System.out.println(Integer.parseInt("21474836 NumberForm
48", 10)); Compilation atException Compiles but
}} error 2.15E+09 at run time no output
97
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 ");
case harrier:
System.out.print("harrier ");
}
}
} Compilation
What is the result? harrier shepherd retriever fails.
98 Given:
static void myFunc()
{
int i, s = 0;
for (int j = 0; j < 7; j++) {
i = 0;
do {
i++;
s++;
} while (i < j);
}
System.out.println(s);
}
} What would be the result 20 21 22 23
99
What is the range of the random number r
generated by the code below?
int r = (int)(Math.floor(Math.random() * 8)) + 2; 2 <= r <= 9 3 <= r <= 10 2<= r <= 10 3 <= r <= 9
100 class Test{
public static void main(String[] args) {
int x=-1,y=-1;
if(++x=++y)
System.out.println("R.T. Ponting");
else
System.out.println("C.H. Gayle");
}
}
consider the code above & select the proper none of the
output from the options. R.T.Ponting C.H.Gayle Compile error listed options
101 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;
o = o + x;
}
System.out.println(o);
}
}
What is the result? 2 24 234 246
102 Consider the following code and choose the
correct output:
class Test{
public static void main(String args[]){
int a=5;
if(a=3){
System.out.print("Three");}else{ Compilation Compiles but
System.out.print("Five");}}} error Three Five no output
103 Given:
public class Batman {
int squares = 81;
public static void main(String[] args) {
new Batman().go();
}
void go() {
incr(++squares);
System.out.println(squares);
}
void incr(int squares) { squares += 10; }
}
What is the result? 81 82 91 92
104 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
{
System.out.println( "ELSE" ) ;
} If a is true If a is true If a is false If a is false
} and b is false and b is true and b is false and b is true
} then the then the then the then the
output is output is "A output is output is
What would be the result? "notB" && B" "ELSE" "ELSE"
105 What is the value of ’n’ after executing the
following code?
int n = 10;
int p = n + 5;
int q = p - 10;
int r = 2 * (p - q);
switch(n)
{
case p: n = n + 1;
case q: n = n + 2;
case r: n = n + 3;
default: n = n + 4; Compilation
} 14 28 Error 10
106 public class While
{
public void loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
{
System.out.print("x plus one is " + (x +
1)); /* Line 8 */
}
} There are There are
} There is a syntax errors syntax errors There is a
syntax error on lines 1 on lines 1, 6, syntax error
Which statement is true? on line 1 and 6 and 8 on line 6
107 Which of the following loop bodies DOES
compute the product from 1 to 10 like (1 * 2 *
3*4*5*
6 * 7 * 8 * 9 * 10)?
int s = 1;
for (int i = 1; i <= 10; i++)
{
<What to put here?>
} s += i * i; s++; s = s + s * i; s *= i;
108 Character
String is a Double has a has a
Which of the following statements are true wrapper compareTo() intValue() Byte extends
regarding wrapper classes? (Choose TWO) class method method Number
109
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 ");
new Rock("granite ");
}
public static void main(String[] a) { new
Mountain(); }
} Compilation granite atom granite atom granite
What is the result? fails. granite granite atom granite
110 What are the thing to be placed to complete
the code?
class Wrap {
public static void main(String args[]) {
int i = iOb.intValue();
int i = 10;
Integer iOb = 100;
i = iOb;
System.out.println(i + " " + iOb);
} No,
} whether this code work properly, if so what Compilation No, Runtime Yes, 100,
would be the result? error error Yes, 10, 100 100
118 Consider the following code and choose the
correct option:
class Test{
public static void main(String args[]){
Long l=0l; Compilation
System.out.println(l.equals(0));}} error true false 1
119 int I = 0;
outer:
while (true)
{
I++;
inner:
for (int j = 0; j < 10; j++)
{
I += j;
if (j == 3)
continue inner;
break outer;
}
continue outer;
}
System.out.println(I);
int count = 1;
while ( ___________ )
{
System.out.print( count + " " );
count = count + 1;
}
System.out.println( );
import java.util.*;
class I
{
public static void main (String[] args)
{
Object i = new ArrayList().iterator();
System.out.print((i instanceof List)+",");
System.out.print((i instanceof
Iterator)+",");
System.out.print(i instanceof ListIterator);
} Prints: false, Prints: false, Prints: false, Prints: false,
} false, false false, true true, false true, true
144
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) + ", ");
}
}
and the invocation:
test("four");
test("tee"); An exception
test("to"); Compilation is thrown at
What is the result? r, t, t, r, e, o, fails. runtime.
145 What will be the output of the program?
int x = 3;
int y = 1;
if (x = y) /* Line 3 */
{ The code
System.out.println("x =" + x); Compilation runs with no
} x=1 x=3 fails. output.
146
import java.util.SortedSet;
import java.util.TreeSet;
System.out.println("the prize.");
You win the You lose the
What does the code fragment prints? prize prize. You win You lose
150 Changes
made in the
Set view
returned by The Map
The return keySet() will interface
type of the be reflected extends the All keys in a
Which statements are true about maps? values() in the original Collection map are
(Choose TWO) method is set map interface unique
151 Which collection implementation is suitable for
maintaining an ordered sequence of
objects,when objects are frequently inserted in
and removed from the middle of the
sequence? TreeMap HashSet Vector LinkedList
152 OutputStrea To write
m is the characters to
abstract an
superclass of Subclasses outputstream, To write an
all classes of the class you have to object to a
that Reader are make use of file, you use
represent an used to read the class the class
outputstream character CharacterOut ObjectFileWri
Choose TWO correct options: of bytes. streams. putStream. ter
153 What is the output :
class One{
public static void main(String[] args) {
int a=100;
if(a>10)
System.out.println("M.S.Dhoni");
else if(a>20)
System.out.println("Sachin");
else if(a>30) M.S.Dhoni
System.out.println("Virat Kohli");} Sachin Virat
} M.S.Dhoni Kohli Virat Kohli all of these
154 A continue If a variable
statement of type int
doesn’t overflows
transfer during the
control to the An overflow execution of
test error can only A loop may a loop, it will
Which of the following statements is TRUE statement of occur in a have multiple cause an
regarding a Java loop? the for loop loop exit points exception
155 switch(x)
{
default:
System.out.println("Hello");
}
Which of the following are acceptable types
for x?
1.byte
2.long
3.char
4.float
5.Short
6.Long 1 ,3 and 5 2 and 4 3 and 5 4 and 6
156 When an
exception When no
occurs then a exception
part of try occurs then
block will complete try
Used to execute one block and
release the appropriate finally block
resources catch block will execute
which are Writing finally and finally but no catch
Which are true with respect to finally block? obtained in block is block will be block will
(Choose THREE) try block. optional. executed. execute.
157 What will happen when you attempt to
compile and run the following code?
public class Bground extends Thread{
public static void main(String argv[]){
Bground b = new Bground();
b.run();
} A compile A run time
public void start(){ time error error
for (int i = 0; i <10; i++){ indicating indicating Clean
System.out.println("Value of i = that no run that no run compile and
" + i); method is method is at run time Clean
} defined for defined for the values 0 compile but
} the Thread the Thread to 9 are no output at
} class class printed out runtime
158 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);
} An exception
What is the result when method testIfA is is thrown at
invoked? true Not true runtime. none
159 A thread will
Both wait() resume
and notify() The wait() execution as The notify()
must be method is soon as its method is
called from a overloaded to sleep overloaded to
Which of the following statements are true? synchronized accept a duration accept a
(Choose TWO) context. duration expires. duration
160 public class MyProgram
{
public static void throwit()
{
throw new RuntimeException();
}
public static void main(String args[])
{
try
{
System.out.println("Hello world "); The program
throwit(); will print
System.out.println("Done with try block Hello world,
"); then will print The program The program
} that a will print will print
finally RuntimeExce Hello world, Hello world,
{ ption has then will print then will print
System.out.println("Finally executing occurred, that a Finally
"); then will print RuntimeExce executing,
} Done with try ption has then will print
} block, and occurred, and that a
} The program then will print then will print RuntimeExce
which answer most closely indicates the will not Finally Finally ption has
behavior of the program? compile. executing. executing. occurred.
161 If a method is capable of causing an
exception that it does not handle, it must
specify this behavior using throws so that
callers of the method can guard themselves
against such Exception false true
162
A) Checked Exception must be explicity
caught or propagated to the calling method
B) If runtime system can not find an
appropriate method to handle the exception,
then the runtime system terminates and uses Only A is Only B is Bothe A and Both A and B
the default exception handler. TRUE TRUE B is TRUE is FALSE
163 public class RTExcept
{
public static void throwit ()
{
System.out.print("throwit ");
throw new RuntimeException();
}
public static void main(String [] args)
{
try
{
System.out.print("hello ");
throwit();
}
catch (Exception re )
{
System.out.print("caught ");
}
finally
{
System.out.print("finally ");
} hello throwit
System.out.println("after "); hello throwit RuntimeExce
} caught finally hello throwit ption caught Compilation
} after caught after fails
164 class s implements Runnable
{
int x, y;
public void run()
{
for(int i = 0; i < 1000; i++)
synchronized(this)
{
x = 12;
y = 12;
}
System.out.print(x + " " + y + " ");
}
public static void main(String args[])
{
s run = new s();
Thread t1 = new Thread(run);
Thread t2 = new Thread(run);
t1.start();
t2.start(); Cannot
} Compilation determine prints 12 12
} What is the output? DeadLock Error output. 12 12
165
What is wrong with the following code?
1.Error
2.Event
3.Object
4.Throwable
5.Exception
6.RuntimeException 1, 2, 3 and 4 2, 3, 4 and 5 1, 4, 5 and 6 2, 4, 5 and 6
169 class X implements Runnable
{
public static void main(String args[])
{
/* Missing code? */
} X run = new
public void run() {} Thread t = X(); Thread t Thread t =
} Thread t = new = new new
Which of the following line of code is suitable new Thread(X); Thread(run); Thread();
to start a thread ? Thread(X); t.start(); t.start(); x.run();
170
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)
{
System.out.println(" Arithmetic Exception");
} compilation ArithmeticExc
System.out.println("finished"); finished Exception fails eption
172 Which of the following methods are static? start() join() yield() sleep()
173 static
methods can static
static be called methods do
methods are using an not have
difficult to object static direct access
maintain, reference to methods are to non-static
because you an object of always methods
can not the class in public, which are
change their which this because they defined
Which of the following statements regarding implementati method is are defined at inside the
static methods are correct? (2 answers) on. defined. class-level. same class.
174 Consider the following code and choose the
correct option:
class Test{
static void display(){
throw new RuntimeException();
} public static void main(String args[]){
try{display();
}catch(Exception e){ throw new
NullPointerException();}
finally{try{ display(); exit
}catch(NullPointerException e){ RuntimeExce
System.out.println("caught");} ption thrown Compilation
finally{ System.out.println("exit");}}}} caught exit exit at run time fails
175 class Test{
public static void main(String[] args){
try{
Integer.parseInt("1.0");
}
catch(Exception e){
System.out.println("Exception occurred");
}
catch(RuntimeException ex){
System.out.println("RuntimeException");
} Exception
}} occurred
consider the code above & select the proper Exception RuntimeExce RuntimeExce does not
output from the options. occurred ption ption compile
176 Which three of the following are methods of
the Object class?
1.notify();
2.notifyAll();
3.isInterrupted();
4.synchronized();
5.interrupt();
6.wait(long msecs);
7.sleep(long msecs);
8.yield(); 1,2,4 2,4,5 1,2,6 2,3,4
177 In the given code snippet
try { int a = Integer.parseInt("one"); }
what is used to create an appropriate catch
block? (Choose all that apply.)
A. ClassCastException
B. IllegalStateException
C. NumberFormatException ClassCastEx NumberForm IllegalStateEx IllegalArgume
D. IllegalArgumentException ception atException ception ntException
178 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{
System.out.println("Finally");
} One Two One Catch One Two
}} Catch Finally One Catch Finally Catch
179 Which digit,and in what order,will be printed
when the following program is run?
Variables can
If a class has be protected
synchronized from
code, concurrent
multiple access
A static threads can problems by When a
method still access marking them thread
cannot be the with the sleeps, it
synchronized nonsynchroni synchronized releases its
Which statement is true? . zed code. keyword. locks
184 Consider the following code and choose the
correct option:
class Test{
static void display(){
throw new RuntimeException();
}
public static void main(String args[]){
try{display();
}catch(Exception e){ } Compiles but
catch(RuntimeException re){} Compiles and Compilation exception at
finally{System.out.println("exit");}}} exit no output fails runtime
185
Given:
public class ExceptionTest
{
class TestException extends Exception {}
public void runTest() throws TestException
{}
public void test() /* Line X */
{
runTest();
}
} throws
At Line X, which code is necessary to make No code is throws throw RuntimeExce
the code compile? necessary Exception Exception ption
186 Implement Implement Extend
java.lang.Run Extend java.lang.Thr java.lang.Run
nable and java.lang.Thr ead and nable and
implement ead and implement override the
Which two can be used to create a new the run() override the the start() start()
Thread? method. run() method. method. method.
187
Except in
An Error that case of VM
might be shutdown, if
thrown in a a try block
Multiple catch method must starts to
A try statements be declared execute, a
statement can catch the as thrown by correspondin
must have at same class of that method, g finally block
least one exception or be handled will always
correspondin more than within that start to
Choose the correct option: g catch block once. method. execute.
188 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; Arithmetic
}} Exception
consider the code above & select the proper Arithmetic Runtime Runtime compilation
output from the options. Exception Exception Exception error
189 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) {
System.out.print("exception "); }
} Compilation finally
What is the result? null fails. exception finally
190 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. } Compilation Compilation Compilation
12. } fails with an fails with an fails with an
What is the result when the second program error on line 5 followed by error on line error on line
is run? (Choose all that apply) 9 an exception 7 8
191
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");
}
Code output:
given that EOFException and Code output: Start Hello
Code output:
FileNotFoundException are both subclasses Start Hello world Catch
Start Hello
of IOException. If this block of code is pasted The code will world File Not Here File not
world End of
in a method, choose the best option. not compile. Found found.
file exception.
192 Any
Any statement
catch(X x) statement that can
can catch that can throw an
subclasses of The Error throw an Exception
X where X is class is a Error must be must be
a subclass of RuntimeExce enclosed in a enclosed in a
Which of the following statements is true? Exception. ption. try block. try block.
193 Consider the following code and choose the
correct option:
int array[] = new int[10]; compiles does not none of the
array[-1] = 0; successfully compile runtime error listed options
194 What will be the output of the program?
class SuperClass
{
public Integer getLength()
{
return new Integer(4);
}
}
class Money {
private String country = "Canada";
public String getC() { return country; } }
class Yen extends Money {
public String getC() { return super.country; } Compiles but
public static void main(String[] args) { Compilation error at run
System.out.print(new Yen().getC() ); } } Canada error time null
236 we must use we must use
always always
extends and implements
later we must and later we we can use in extends and
When we use both implements & extends use must use any order its implements
keywords in a single java program then what implements extends not at all a can't be used
is the order of keywords to follow? keyword. keyword. problem together
237 Consider the code below & select the correct
ouput from the options:
1. public class Mountain {
2. protected int height(int x) { return 0; }
3. }
4. class Alps extends Mountain {
5. // insert code here
6. }
Which five methods, inserted independently at
line 5, will compile? (Choose three.)
A. public int height(int x) { return 0; }
B. private int height(int x) { return 0; }
C. private int height(long x) { return 0; }
D. protected long height(long x) { return 0; }
E. protected long height(int x) { return 0; } A,B,E A,C,D B,D,E C,D,E
238 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);
}
void doStuff(int s) {
s += Easy + ++s;
System.out.println("s " + s);
} Compilation
} What is the result? s 14 s 16 s 10 fails.
239 Given:
interface A { public void methodA(); }
interface B { public void methodB(); }
interface C extends A,B{ public void
methodC(); } //Line 3 If you define If you define
class D implements B { D e = (D) D e = (D)
public void methodB() { } //Line 5 (new E()), (new E()),
} then then
class E extends D implements C { //Line 7 e.methodB() e.methodB()
public void methodA() { } invokes the invokes the
public void methodB() { } //Line 9 Compilation version of Compilation version of
public void methodC() { } fails, due to methodB() fails, due to methodB()
} an error in defined at an error in defined at
What would be the result? line 3 line 9 line 7 line 5
240 It must be It must be
used in the used in the
It can only be last first
used in the Only one statement of statement of
Which of the following statements is true parent's child class the the
regarding the super() method? constructor can use it constructor. constructor.
241
Consider the following code and choose the
correct option:
interface Output{
void display();
void show();
}
class Screen implements Output{
void show() {System.out.println("show");}
void display(){ System.out.println("display"); Compiles but
}public static void main(String[] args) { Compilation error at run Runs but no
new Screen().display();}} display error time output
242 Consider the following code and choose the
correct option:
class A{
void display(){ System.out.println("Hello A");
}}
class B extends A{
void display(){
System.out.println("Hello B"); }}
public class Test {
public static void main(String[] args) { Compiles but
B b=(B) new A(); Compilation error at
b.display(); }} Hello A error Hello B runtime
243 Consider the following code:
// Class declarations: Definitely
class Super {} legal at Definitely
class Sub extends Super {} runtime, but legal at
// Reference declarations: Legal at the cast runtime, and
Super x; compile time, operator the cast
Sub y; but might be (Sub) is not operator
Which of the following statements is correct Illegal at illegal at strictly (Sub) is
for the code: y = (Sub) x? compile time runtime needed. needed.
244 Given:
11. class ClassA {}
12. class ClassB extends ClassA {}
13. class ClassC extends ClassA {}
and:
21. ClassA p0 = new ClassA();
22. ClassB p1 = new ClassB();
23. ClassC p2 = new ClassC();
24. ClassA p3 = new ClassB();
25. ClassA p4 = new ClassC(); p1 =
Which TWO are valid? (Choose two.) p0 = p1; p2 = p4; (ClassB)p3; p1 = p2;
245 Consider the following code and choose the
correct option:
abstract class Car{
abstract void accelerate();
}
class Lamborghini extends Car{
@Override
void accelerate() {
System.out.println("90 mph"); }
void nitroBooster(){
System.out.print("150 mph"); }
public static void main(String[] args) {
Car mycar=new Lamborghini(); Compiles but
Lamborghini lambo=(Lamborghini) mycar; Compilation error at
lambo.nitroBooster();}} 150 mph error 90 mph runtime
246 Consider the following code and choose the
correct option:
class A{
void display(){ System.out.println("Hello A");
}}
class B extends A{
void display(){
System.out.println("Hello B"); }}
public class Test {
public static void main(String[] args) {
A a=new B(); Compiles but
B b= (B)a; Compilation error at
b.display(); }} Hello A error Hello B runtime
247 Because of
Because of single Because of Because of
single inheritance, single single
inheritance, Mammal can inheritance, inheritance,
Mammal can have no other Animal can Mammal can
A class Animal has a subclass Mammal. have no parent than have only have no
Which of the following is true: subclasses Animal one subclass siblings.
248
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();
a.makeNoise();
}
}
consider the code above & select the proper
output from the options. run time error generic noise bark compile error
249 What will be the result when you try to
compile and run the following code?
class Base1 {
Base1() {
int i = 100;
System.out.println(i);
}
}
Given:
class Pizza {
java.util.ArrayList toppings;
public final void addTopping(String topping) {
toppings.add(topping);
}
}
public class PepperoniPizza extends Pizza {
public void addTopping(String topping) {
System.out.println("Cannot add Toppings");
}
public static void main(String[] args) {
Pizza pizza = new PepperoniPizza();
pizza.addTopping("Mushrooms"); A
} The code NullPointerEx
} Compilation Cannot add runs with no ception is
What is the result? fails. Toppings output. thrown
255 Consider the following code and choose the
correct option:
interface console{
int line=10;
void print();}
class a implements console{
void print(){
System.out.print("A");} Compiles but
public static void main(String ar[]){ Compilation error at run Runs but no
new a().print();}} A error time output
256 private final public static
Which of these field declarations are legal in public int final static int static int int answer =
an interface? (Choose all applicable) answer = 42; answer = 42; answer = 42; 42;
257 Given :
No—there No—but a Yes—an
Day d; must always object of object can be
BirthDay bd = new BirthDay("Raj", 25); be an exact parent type assigned to a Yes—any
d = bd; // Line X match can be reference object can be
between the assigned to a variable of assigned to
Where Birthday is a subclass of Day. State variable and variable of the parent any reference
whether the code given at Line X is correct: the object child type. type. variable.
258
If both a If neither
subclass and super() nor
its superclass this() is
do not have declared as
A super() or any declared the first If super() is
this() call constructors, statement in the first
must always the implicit the body of a statement in
be provided default constructor, the body of a
explicitly as constructor of this() will constructor,
the first the subclass implicitly be this() can be
statement in will call inserted as declared as
the body of a super() when the first the second
Select the correct statement: constructor. run statement. statement
259
public final static final final data
data type data type type
Choose the correct declaration of variable in varaibale=inti static data varaiblename variablename
an interface: alization; type variable; ; =intialization;
260 Consider the following code and choose the
correct option:
abstract class Fun{
void time(){
System.out.println("Fun Time"); }}
class Run extends Fun{
void time(){
System.out.println("Fun Run"); }
public static void main(String[] args) { Compiles but
Fun f1=new Run(); Compilation error at
f1.time(); }} Fun Time error Fun Run runtime
261
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){
ThreeWheeler obj = new ThreeWheeler();
obj.drive();
}}
consider the code above & select the proper
output from the options. Auto Bicycle Auto compile error runtime error
262
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 static void main(String[] args) {
perEmp emp=new Programmer(); sal details compilation per details
emp.saldetails(); }} sal details per details error sal details
263 All data members in an interface are by abstract and public and public ,static default and
default final abstract and final abstract
264 Consider the following code and choose the
correct option:
interface console{
int line;
void print();}
class a implements console{
public void print(){
System.out.print("A");} Compiles but
public static void main(String ar[]){ Compilation error at run Runs but no
new a().print();}} A error time output
265
An abstract
class is one
An abstract which
class is one contains An abstract
which some defined class is one
contains methods and which
general some contains only Abstract
Which of the following is correct for an purpose undefined static class can be
abstract class. (Choose TWO) methods methods methods declared final
266
abstract class
Vehicle {
abstract class abstract class abstract abstract void
Vehicle { Vehicle { Vehicle { display(); {
Which of the following defines a legal abstract abstract void abstract void abstract void System.out.pr
class? display(); } display(); } display(); } intln("Car"); }}
267 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() { }
} Compilation Compilation
of class A will of class B will
class B extends A { Compilation Compilation fail. fail.
public void doSomething() throws of both of both Compilation Compilation
SomeException { } classes A & classes will of class B will of class A will
} B will fail succeed succeed succeed
269 No—if a
class
implements
several Yes— either
interfaces, of the two
each variables can Yes—since
constant No—a class be accessed the
must be may not through : definitions
Is it possible if a class definition implements defined in implement interfaceNam are the same
two interfaces, each of which has the same only one more than e.variableNa it will not
definition for the constant? interface one interface me matter
270
The
An overriding parameter list
method can of an
declare that it overriding
throws method can
checked be a subset
Private A subclass exceptions of the
methods can override that are not parameter list
cannot be any method thrown by the of the method
overridden in in a method it is that it is
Select the correct statement: subclasses superclass overriding overriding
271 Consider the following code and choose the
correct option:
class A{
void display(){ System.out.println("Hello A");
}}
class B extends A{
void display(){
System.out.println("Hello B"); }}
public class Test {
public static void main(String[] args) {
A a=new B(); Compiles but
B b= a; Compilation error at
b.display(); }} Hello A error Hello B runtime
272 Helps the
compiler to
find the
source file
that
corresponds
to a class, Helps
when it does Javadoc to
not find a Helps JVM to build the
Which of the following option gives one To maintain class file find and Java
possible use of the statement 'the name of the the uniform while execute the Documentati
public class should match with its file name'? standard compiling classes on easily
273
Holds the Holds the
location of Holds the location of
Core Java location of User Defined Holds the
Class Library Java classes, location of
Which of the following statement gives the (Bootstrap Extension packages Java
use of CLASSPATH? classes) Library and JARs Software
274
Sub
Packages Packages packages
can contain can contain should be
both Classes non-java declared as
Packages and elements private in
can contain Interfaces such as order to deny
Which of the following are true about only Java (Compiled images, xml importing
packages? (Choose 2) Source files Classes) files etc. them
275 Which of the following options give the valid
argument types for main() method? (Choose
2) String [][]args String args[] String[] args[] String[] args
276
[email protected]
Which of the following options give the valid dollorpack.$p _score.pack. [email protected]
package names? (Choose 3) ack.$$pack $$.$$.$$ __pack erp@ckage
277 Object class
provides the
Object class method for
has the core Set
Object class methods for implementati
Object class cannot be thread on in
Which of the following statements are true is an abstract instantiated synchronizati Collection
regarding java.lang.Object class? (Choose 2) class directly on framework
278 Java
Java Java Runtime Database
The term 'Java Platform' refers to Compiler Environment Connectivity Java
________________. (Javac) (JRE) (JDBC) Debugger
279 registerDriver
() method
and
Which of the following methods are needed registerDriver Class.forNam Class.forNam getConnectio
for loading a database driver in JDBC? () method e() e() n
280
Using the
static method
registerDriver
() method
Using which is Either
forName() available in forName() or
which is a DriverManag registerDriver None of the
how to register driver class in the memory? static method er Class. () given options
281 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
} What should be imported related to java.sql.Resu java.sql.Drive java.sql.Drive java.sql.Conn
ResultSet? ltSet r rManager ection
282
Consider the following code & select the
correct option for output.
String sql ="select empno,ename from emp";
PreparedStatement
pst=cn.prepareStatement(sql);
System.out.println(pst.toString());
ResultSet rs=pst.executeQuery(); will show first Compiles but
System.out.println(rs.getString(1)+ " employee Compilation error at run Compiles but
"+rs.getString(2)); record error time no output
283
Which of the following methods finds the Connection.g ResultSetMet DatabaseMet Database.get
maximum number of connections that a etMaxConne aData.getMa aData.getMa MaxConnecti
specific driver can obtain? ctions xConnections xConnections ons
284 By default all JDBC transactions are
autocommit. State TRUE/FALSE. true false
285 DriverManag Driver ResultSet Statement
getConnection() is method available in? er Class Interface Interface Interface
286 A) By default, all JDBC transactions are auto
commit
B) PreparedStatement suitable for dynamic
sql and requires one time compilation
C) with JDBC it is possible to fetch information Only A and B Only B and C Both A and C
about the database is TRUE is True is TRUE All are TRUE
287 It returns int
value as
mentioned
below: > 0 if
many
columns
Contain Null
Value < 0 if
It returns true no column
when last contains Null
There is no read column Value = 0 if
such method contain SQL one column
What is the use of wasNull() in ResultSet in ResultSet NULL else contains Null none of the
interface? interface returns false value listed options
288 Given :
public class MoreEndings {
public static void main(String[] args) throws
Exception {
Class driverClass =
Class.forName("sun.jdbc.odbc.JdbcOdbcDrive
r");
DriverManager.registerDriver((Driver)
driverClass.newInstance()); java.sql.Drive
// Some code r
} Inorder to compile & execute this code, what java.sql.Drive java.sql.Drive java.sql.Drive java.sql.Data
should we import? r r rManager Source
289
Which of the following method can be used to
execute to execute all type of queries i.e. executeAllSQ executeQuer
either Selection or Updation SQL Queries? executeAll() L() execute() y()
290
Which method will return boolean when we try executeUpda executeSQL( executeQuer
to execute SQL Query from a JDBC program? te() ) execute() y()
291
Cosider the following code & select the
correct output.
String sql ="select rollno, name from student";
PreparedStatement
pst=cn.prepareStatement(sql);
System.out.println(pst.toString());
ResultSet rs=pst.executeQuery(); Compiles but
while(rs.next()){ will show only Compilation error at run
System.out.println(rs.getString(3)); } name error will show city time
292
It is possible to insert/update record in a table
by using ResultSet. State TRUE/FALSE true false
293 Read only, Updatable,
What is the default type of ResultSet in JDBC Read Only, Updatable, Scroll Scroll
applications? Forward Only Forward only Sensitive sensitive
294 An application can connect to different
Databases at the same time. State
TRUE/FALSE. true false
295 A) It is not possible to execute select query
with execute() method
B) CallableStatement can executes store Both A and B Only A is Only B is Both A and B
procedures only but not functions is FALSE TRUE TRUE is TRUE
296 A) When one use callablestatement, in that
case only parameters are send over network
not sql query.
B) In preparestatement sql query will compile Both A and B Both A and B Only A is Only B is
for first time only is FALSE is TRUE TRUE TRUE
297 Consider the code below & select the correct
ouput from the options:
Rodent rod;
Rat rat = new Rat();
Mouse mos = new Mouse();
PocketMouse pkt = new PocketMouse();
class Accounts
{
public double calculateBonus(){//method's
code} Simple
} Aggregation Association Dependency Composition
339
Given classes A, B, and C, where B extends
A, and C extends B, and where all classes
implement the instance method void doIt().
How can the doIt() method in A be It is not his.super.doIt ((A)
called from an instance method in C? possible super.doIt() () this).doIt();
340 int [] a =
Which of the following will declare an array Array a = {23,22,21,20, int a [] = new
and initialize it with five numbers? new Array(5); 19}; int[5]; int [5] array;
341 Which of the following are correct variable
names? (Choose TWO) int #ss; int 1ah; int _; int $abc;
342 What is the output of the following:
int a = 0;
int b = 10;
a = --b ;
System.out.println("a: " + a + " b: " + b ); a: 9 b:11 a: 10 b: 9 a: 9 b:9 a: 0 b:9
343 As per the following code fragment, what is
the value of a?
String s;
int a;
s = "Foolish boy.";
a = s.indexOf("fool"); -1 0 4 random value
344 Consider the following code snippet:
int i = 10;
int n = i++%5;
What are the values of i and n after the code
is executed? 10, 1 11, 1 10,0 11,0
345 Consider the following code and choose the
correct output:
int value = 0;
int count = 1;
value = count++ ;
System.out.println("value: "+ value + " count: value: 0 value: 0 value: 1 value: 1
" + count); count: 0 count: 1 count: 1 count: 2
346 Consider the following code and select the
correct output:
class Test{
interface Y{
void display(); }
public static void main(String[] args) {
new Y(){
public void display(){ Compiles but Compiles but
System.out.println("Hello World"); } }; Compilation error at run run without
}} Hello World error time output
347
What is the output of the following program?
public class demo {
public static void main(String[] args) {
int arr[5];
for (int i = 0; i < arr.length; i++) {
arr[i] = arr[i] + 10;
}
for (int j = 0; j < arr.length; j++)
System.out.println(arr[j]); A sequence
A sequence of Garbage
} of five 10's Values are compile time Compiles but
} are printed printed Error no output
348 Which of the following methods registers a
thread in a thread scheduler? run(); construct(); start(); register();
349 class PingPong2 {
synchronized void hit(long n) {
for(int i = 1; i < 3; i++)
System.out.print(n + "-" + i + " ");
}
}
public class Tester implements Runnable {
static PingPong2 pp2 = new PingPong2();
public static void main(String[] args) {
new Thread(new Tester()).start();
new Thread(new Tester()).start();
}
public void run() {
pp2.hit(Thread.currentThread().getId()); } The output The output The output The output
} could be 5-1 could be 6-1 could be 6-1 could be 6-1
Which statement is true? 6-1 6-2 5-2 6-2 5-1 5-2 5-2 6-2 5-1 6-2 5-1 7-1
350 Consider the following code and choose the
correct option:
class Cthread extends Thread{
public void run(){
System.out.print("Hi");}
public static void main (String args[]){
Cthread th1=new Cthread(); will print Hi
th1.run(); twice and
th1.start(); throws
th1.run(); Exception at will print Hi Compilation will print Hi
}} run time Thrice error once
351 class Cthread extends Thread{
public void run(){
System.out.print("Hi");}
public static void main (String args[]){
Cthread th1=new Cthread(); will print Hi
th1.run(); twice and
th1.start(); throws
th1.start(); will start two will print Hi exception at
}} thread Once will not print runtime
352 Consider the following code and choose the
correct option:
class Cthread extends Thread{
Cthread(){start();}
public void run(){
System.out.print("Hi");} will create
public static void main (String args[]){ two child
Cthread th1=new Cthread(); threads and will not create
Cthread th2=new Cthread(); display Hi compilation any child will display Hi
}} twice error thread once
353 Which of the following methods are defined in
class Thread? (Choose TWO) start() wait() notify() run()
354 The following block of code creates a Thread
using a Runnable target:
EqTest(){
String s="Java";
String s2="java";
// Line X
{
System.out.println("Equal");
}else
{
System.out.println("Not equal");
}
} if(s.equals(s2 if(s.equalsIgn if(s.noCaseM
} if(s==s2) )) oreCase(s2)) atch(s2))
394 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
}
}
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
cd Compilation
What is the result? ab Error ab cd abcd
403 Consider the following code and choose the
correct option:
class std{
int call; std(int c){call=c;}
int getCall(){return call;}
}
public class Test{
public static void main(String[] args) throws
IOException {
File file=new File("d:/std.txt");
FileOutputStream fos=new
FileOutputStream(file);
ObjectOutputStream oos=new
ObjectOutputStream(fos); the state of
std s1=new std(10); the state of the object s1
oos.writeObject(s1); the object s1 Compiles but will not be
oos.close(); will be store Compilation error at run store to the
}} to file std.txt error time file.
404 Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) {
File file=new File("D:/jlist.lst");
byte buffer[]=new byte[(int)file.length()+1]; reads data
FileInputStream fis=new reads data from file
FileInputStream(file); from file named jlist.lst
fis.read(buffer); named jlist.lst in byte form
System.out.println(buffer); in byte form and display Compiles but
} and display it Compilation garbage error at
} on console. error value runtime
405 Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) throws
IOException { reads data
File file=new File("D:/jlist.lst"); reads data from file
byte buffer[]=new byte[(int)file.length()+1]; from file named jlist.lst
FileInputStream fis=new named jlist.lst in byte form
FileInputStream(file); in byte form and display Compiles but
fis.read(buffer); and display it Compilation
garbage error at
System.out.println(new String(buffer)); }} on console. error value runtime
406 throws a
What happens when the constructor for throws a throws a ArrayIndexOu
FileInputStream fails to open a file for DataFormatE FileNotFound tOfBoundsEx
reading? xception Exception ception returns null
407 Consider the following code and choose the
correct option: creates Compiles and
public class Test { directories executes but
public static void main(String[] args) { names prj Compiles but directories
File file=new File("d:/prj,d:/lib"); and lib in d: Compilation error at run are not
file.mkdirs();}} drive error time created
408 Consider the following code and choose the
correct output:
public class Person{
public void talk(){ System.out.print("I am a
Person "); }
}
public class Student extends Person {
public void talk(){ System.out.print("I am a
Student "); }
}
what is the result of this piece of code:
public class Test{
public static void main(String args[]){
Person p = new Student();
p.talk(); I am a I am a
} I am a I am a Person I am Student I am
} Person Student a Student a Person
409 Which of these are two legal ways of
accessing a File named "file.tst" for reading.
Select the correct option:
A)FileReader fr = new FileReader("file.tst");
B)FileInputStream fr = new
FileInputStream("file.tst");
C)InputStreamReader isr = new
InputStreamReader(fr, "UTF8");
D)FileReader fr = new FileReader("file.tst",
"UTF8"); A,D B,C C,D A,B
410 What is the DataOutputStream method that
writes double precision floating point values to
a stream? writeBytes() writeFloat() write() writeDouble()
411 Consider the following code and choose the
correct option:
public class Test{
public static void main(String[] args) {
File dir = new File("dir"); The file
dir.mkdir(); The file The file system has a
File f1 = new File(dir, "f1.txt"); try { The file system has a system has a directory
f1.createNewFile(); } catch (IOException e) { system has a new empty directory named
;} new empty directory named dir, newDir,
File newDir = new File("newDir"); directory named containing a containing a
dir.renameTo(newDir);} } named dir newDir file f1.txt file f1.txt
412
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) throws
IOException {
File file=new File("d:/data");
byte buffer[]=new byte[(int)file.length()+1];
FileInputStream fis=new Compiles and
FileInputStream(file); Transfer runs but
fis.read(buffer); content of file Compiles but content not
FileWriter fw=new FileWriter("d:/temp.txt"); data to the Compilation error at transferred to
fw.write(new String(buffer));}} temp.txt error runtime the temp.txt
413
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
public class MoreEndings {
public static void main(String[] args) {
try {
FileInputStream fis = new
FileInputStream("seq.txt");
InputStreamReader isr = new
InputStreamReader(fis);
int i = isr.read();
while (i != -1) {
System.out.print((char)i + "|");
i = isr.read();
}
} catch (FileNotFoundException fnf) {
System.out.println("File not found");
} catch (EOFException eofe) {
System.out.println("End of stream");
} catch (IOException ioe) {
System.out.println("Input error");
} The program
} will not
} compile The program
Assume that the file "seq.txt" exists in the because a The program The program will compile,
current directory, has the required certain will compile will compile print H|e|l|l|o|,
access permissions, and contains the string unchecked and print and print and then
"Hello". exception is H|e|l|l|o|Input H|e|l|l|o|End terminate
Which statement about the program is true? not caught. error. of stream. normally.
414 Consider the following code and choose the
correct option:
public class Test{ Skip the first
public static void main(String[] args) throws seven
IOException { characters
File file = new File("d:/temp.txt"); and then
FileReader reader=new FileReader(file); starts reading
reader.skip(7); int ch; file and Compiles and Compiles but
while((ch=reader.read())!=-1){ display it on Compilation runs without error at
System.out.print((char)ch); } }} console error output runtime
415 The file is
modified from
A file is readable but not writable on the file A being
system of the host platform. What will SecurityExce The boolean The boolean unwritable to
be the result of calling the method canWrite() ption is value false is value true is being
on a File object representing this file? thrown returned returned writable.
416 void add(int void add(int void add(int
x,int y) char char add(float x,int y) char x,int y) void
Which of following set of functions are add(int x,int x) char add(char sum(double
example of method overloading y) add(float y) x,char y) x,double y)
417
Efficient avoiding
utilization of Code method name
What is the advantage of runtime memory at flexibility at confusion at
polymorphism? runtime Code reuse runtime runtime
418
Which of the following is an example of IS A Microprocess
relationship? Ford - Car or - Computer Tea -Cup Driver -Car
419 Which of the following is not a valid relation Segmentatio
between classes? Inheritance n Instantiation Composition
420 Which of the following is not an attribute of
object? State Behaviour Inheritance Identity