Core Java Assessment MCQS

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 95

SubBank QuestionText QuestionType Choice1 Choice2 Choice3 Choice4 Choice5 Grade1 Grade2 Grade3 Grade4 Grade5

What will be the result of compiling the


following program? A compilation
public class MyClass { error will
long var; A compilation A compilation occur at (Line
public void MyClass(long param) { var = error will error will no 2), since
param; } // (Line no 1) occur at (Line occur at (2), the class
Access public static void main(String[] args) { no 1), since since the does not have
Specifiers MyClass a, b; constructors class does a constructor The program
Constructors a = new MyClass(); // (Line no 2) cannot not have a that takes will compile
Methods } specify a default one argument without
NewQB } MCQ return value constructor of type int. errors. 0 0 0 1
Access
Specifiers
Constructors
Methods Which of the following declarations are boolean b = String s = int i = new
NewQB correct? (Choose TWO) MCA TRUE; byte b = 256; “null”; Integer(“56”); 0 0 0.5 0.5

What will happen when you attempt to


compile and run this code?
abstract class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}

public class Abs extends Base{


public static void main(String argv[]){
Abs a = new Abs();
a.amethod(); The compiler
} The code will will complain
public void myfunc(){ compile but that the
System.out.println("My Func"); The compiler complain at method
Access } The code will will complain run time that myfunc in the
Specifiers public void amethod(){ compile and that the Base the Base base class
Constructors myfunc(); run, printing class has class has has no body,
Methods } out the words non abstract non abstract nobody at all
NewQB } MCQ "My Func" methods methods to print it 1 0 0 0
Constructor Constructor Constructor Constructor
Access class A, B and C are in multilevel inheritance of A executes of C executes of C executes of A executes
Specifiers hierarchy repectively . In the main method of first, followed first followed first followed first followed
Constructors some other class if class C object is created, by the by the by the by the
Methods in what sequence the three constructors constructor of constructor of constructor of constructor of
NewQB execute? MCQ B and C A and B B and A C and B 1 0 0 0
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 Compiles and Compiles but Compiles and
NewQB System.out.print(new S().roll);}} MCQ error display 1 no output diplay 0 1 0 0 0
Here is the general syntax for method
definition:
The The
accessModifier returnType returnValue returnValue
methodName( parameterList ) can be any must be the
{ type, but will same type as
Java statements be the
automatically returnType, or The
return returnValue; converted to If the be of a type returnValue
Access } returnType returnType is that can be must be
Specifiers when the void then the converted to exactly the
Constructors method returnValue returnType same type as
Methods What is true for the returnType and the returns to the can be any without loss the
NewQB returnValue? MCQ caller type of information returnType. 0 0 1 0
Access
Specifiers A) A call to instance method can not be made
Constructors from static context.
Methods B) A call to static method can be made from Both are Both are Only A is Only B is
NewQB non static context. MCQ FALSE TRUE TRUE TRUE 0 1 0 0
Consider the following code and choose the
Access correct option:
Specifiers class A{ A(){System.out.print("From A");}} Compiles but
Constructors class B extends A{ B(int z){z=2;} throws
Methods public static void main(String args[]){ Compilation Comiples and runtime Compiles and
NewQB new B(3);}} MCQ error prints From A exception display 3 0 1 0 0

class Sample
{int a,b;
Sample()
{ a=1; b=2;
System.out.println(a+"\t"+b);
}
Sample(int x)
{ this(10,20);
a=b=x;
System.out.println(a+"\t"+b);
}
Sample(int a,int b)
{ this();
this.a=a;
this.b=b;
System.out.println(a+"\t"+b);
}
}
class This2
{ public static void main(String args[])
Access {
Specifiers Sample s1=new Sample (100);
Constructors }
Methods } 100 100 1 2 1 2 100 100 10 20 1 2 100 1 2 10 20 100
NewQB What is the Output of the Program? MCQ 10 20 10 20 100 100 0 0 0 1
Consider the following code and choose the
Access correct option:
Specifiers class A{ private static void display() Compiles and Compiles but
Constructors { System.out.print("Hi");} throw run doesn't
Methods public static void main(String ar[]){ Compiles and time display Compilation
NewQB display();}} MCQ display Hi exception anything fails 1 0 0 0
Consider the following code and choose the
Access correct option: code
Specifiers package aj; class A{ protected int j; } code compiles but
Constructors package bj; class B extends A compiles fine will not
Methods { public static void main(String ar[]){ and will display compliation j can not be
NewQB System.out.print(new A().j=23);}} MCQ display 23 output error initialized 0 0 1 0
Consider the following code and choose the
Access correct option:
Specifiers class A{ int z; A(int x){z=x;} } Compiles but
Constructors class B extends A{ throws run Compiles and
Methods public static void main(String arg){ Compilation time displays None of the
NewQB new B();}} MCQ error exception nothing listed options 1 0 0 0

class Test{
static void method(){
this.display();
}
static display(){
System.out.println(("hello");
}
public static void main(String[] args){
Access new Test().method();
Specifiers }
Constructors }
Methods consider the code above & select the proper compiles but does not
NewQB output from the options. MCQ hello Runtime Error no output compile 0 0 0 1

What will be the result when you try to


compile and run the following code?
private class Base{
Base(){
int i = 100;
System.out.println(i);
}
}

public class Pri extends Base{


static int i = 200;
Access public static void main(String argv[]){
Specifiers Pri p = new Pri();
Constructors System.out.println(i);
Methods } 100 followed Compile time
NewQB } MCQ 200 by 200 error 100 0 0 1 0
public class MyClass {
static void print(String s, int i) {
System.out.println("String: " + s + ", int: "
+ i);
}

static void print(int i, String s) {


System.out.println("int: " + i + ", String: " +
s);
}

Access public static void main(String[] args) { String: String int: 27,
Specifiers print("String first", 11); first, int: 11 String: Int
Constructors print(99, "Int first"); int: 99, first String:
Methods } String: Int String first, Compilation Runtime
NewQB }What would be the output? MCQ first int: 27 Error Exception 1 0 0 0

A) No argument constructor is provided to all


Java classes by default
B) No argument constructor is provided to the
Access class only when no constructor is defined.
Specifiers C) Constructor can have another class object
Constructors as an argument
Methods D) Access specifiers are not applicable to Only A is B and C is All are
NewQB Constructor MCQ TRUE All are TRUE TRUE FALSE 0 0 1 0
Consider the following code and choose the
correct option:
class Test{ private static void display(){
Access System.out.println("Display()");}
Specifiers private static void show() { display(); Compiles and Compiles but
Constructors System.out.println("show()");} prints throws
Methods public static void main(String arg[]){ Compiles and Display() runtime Compilation
NewQB show();}} MCQ prints show() show() exception error 0 1 0 0
Which of the following sentences is true?
A) Access to data member depends on the
scope of the class and the scope of data
members
Access B) Access to data member depends only on
Specifiers the scope of the data members
Constructors C) Access to data member depends on the
Methods scope of the method from where it is Only A and C All are Only A is
NewQB accessed MCQ is TRUE All are TRUE FALSE TRUE 0 0 0 1
Given:
public class Yikes {

public static void go(Long n)


{System.out.print("Long ");}
public static void go(Short n)
{System.out.print("Short ");}
public static void go(int n)
{System.out.print("int ");}
public static void main(String [] args) {
short y = 6;
long z = 7;
Access go(y);
Specifiers go(z);
Constructors } An exception
Methods } Compilation is thrown at
NewQB What is the result? MCQ int Long Short Long fails. runtime. 1 0 0 0
Access
Specifiers
Constructors System.out.p System.out.p System.out.p System.out.p
Methods rintln(Math.ce rintln(Math.flo rintln(Math.ro rintln(Math.mi
NewQB Which of the following will print -4.0 MCQ il(-4.7)); or(-4.7)); und(-4.7)); n(-4.7)); 1 0 0 0
Suppose class B is sub class of class A:
A) If class A doesn't have any constructor,
then class B also must not have any
constructor
B) If class A has parameterized constructor,
Access then class B can have default as well as
Specifiers parameterized constructor
Constructors C) If class A has parameterized constructor
Methods then call to class A constructor should be Only B and C Only A is All are Only A and C
NewQB made explicitly by constructor of class B MCQ is TRUE TRUE FALSE is TRUE 1 0 0 0

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 Dog Man Cat
NewQB output from the options. MCQ Dog Ant Ant Man Dog Ant Dog Man Ant 1 0 0 0
Consider the following code and choose the
Access correct option:
Specifiers class A{ private void display() Compiles but Compiles and
Constructors { System.out.print("Hi");} doesn't throws run
Methods public static void main(String ar[]){ display time Compilation Compiles and
NewQB display();}} MCQ anything exception fails displays Hi 0 0 1 0
Consider the following code and choose the
correct option:
public class MyClass {
public static void main(String arguments[]) {
amethod(arguments);
}
public void amethod(String[] arguments) {
Access System.out.println(arguments[0]);
Specifiers System.out.println(arguments[1]);
Constructors }
Methods } prints Hi Compiler Runs but no
NewQB Command Line arguments - Hi, Hello MCQ Hello Error output Runtime Error 0 1 0 0

package QB;
class Sphere {
protected int methodRadius(int r) {
System.out.println("Radious is: "+r);
return 0;
}
}
package QB;
public class MyClass {
public static void main(String[] args) {
double x = 0.89;
Access Sphere sp = new Sphere();
Specifiers // Some code missing
Constructors }
Methods } to get the radius value what is the code of methodRadiu sp.methodRa Nothing to Sphere.meth
NewQB line to be added ? MCQ s(x); dius(x); add odRadius(); 0 1 0 0

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(); compiles
Constructors }} successfully
Methods consider the code above & select the proper but runtime
NewQB output from the options. MCQ 0,0 error compile error none of these 0 0 1 0
Consider the following code and choose the
correct option:
class Test{ private void display(){
Access System.out.println("Display()");}
Specifiers private static void show() { display(); Compiles and Compiles but
Constructors System.out.println("show()");} prints throws
Methods public static void main(String arg[]){ Compiles and Display() runtime Compilation
NewQB show();}} MCQ prints show() show() exception error 0 0 0 1
Consider the following code and choose the
best option:
Access class Super{ int x; Super(){x=2;}}
Specifiers class Sub extends Super { void displayX(){
Constructors System.out.print(x);} Compiles and
Methods public static void main(String args[]){ Compilation runs without Compiles and Compiles and
NewQB new Sub().displayX();}} MCQ error any output display 2 display 0 0 0 1 0

class One{
int var1;
One (int x){
var1 = x;
}}
class Derived extends One{
int var2;
Derived(){
super(10);
var2=10;
}
void display(){
System.out.println("var1="+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 var1=10 ,
NewQB output from the options. MCQ var2=10 0,0 compile error runtime error 1 0 0 0

public class MyAr {


static int i1;
public static void main(String argv[]) {
MyAr m = new MyAr();
m.amethod();
} It is not
Access public void amethod() { possible to
Specifiers System.out.println(i1); access a
Constructors } static variable
Methods } Compilation Garbage in side of non
NewQB What is the output of the program? MCQ Error Value static method 1 0 0 0
What will be printed out if you attempt to
compile and run the following code ?
public class AA {
public static void main(String[] args) {
int i = 9;
switch (i) {
default:
System.out.println("default");
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
Access case 2:
Specifiers System.out.println("two");
Constructors }
Methods } Compilation default zero
NewQB } MCQ Error default default zero one two 0 0 1 0
Which statements, when inserted at (1), will
not result in compile-time errors?
public class ThisUsage {
int planets;
static int suns;
Access public void gaze() {
Specifiers int i;
Constructors // (1) INSERT STATEMENT HERE
Methods } i= this = new this.suns =
NewQB } MCA this.planets; i = this.suns; ThisUsage(); this.i = 4; planets; 0.33 0.33 0 0 0.33
Access
Specifiers
Constructors
Methods Which modifier is used to control access to
NewQB critical code in multi-threaded programs? MCQ default public transient synchronized 0 0 0 1
Given:
package QB;

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()
Access } Meal() Cheese() Lunch() Sandwich()
Specifiers public class MyClass7 { Lunch() Lunch() PortableLunc Meal()
Constructors public static void main(String[] args) { PortableLunc PortableLunc h() Lunch()
Methods new Sandwich(); h() Cheese() h() Sandwich() PortableLunc
NewQB } MCQ Sandwich() Sandwich() Cheese() h() 1 0 0 0
Consider the following code and choose the
correct option:
class A{ int a; A(int a){a=4;}}
Access class B extends A{ B(){super(3);} void
Specifiers displayA(){
Constructors System.out.print(a);}
Methods public static void main(String args[]){ compiles and compilation Compiles and Compiles and
NewQB new B().displayA();}} MCQ display 0 error display 4 display 3 1 0 0 0
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:
Access public void amethod(int x){ amethod
Specifiers x=x*2; parameter
Constructors j=j*2; does not
Methods } match
NewQB } MCQ variable 20 and 40 10 and 40 10, and 20 0 0 1 0
The compiler
will
automatically The program
Access change the The compiler will compile
Specifiers What will happen if a main() method of a private will find the The program successfully,
Constructors "testing" class tries to access a private variable to a error and will will compile but the .class
Methods instance variable of an object using dot public not make and run file will not
NewQB notation? MCQ variable a .class file successfully run correctly 0 1 0 0

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) {
Access public static void main(String... a) {
Specifiers public static void main(String[]... a) {
Constructors public static void main(String...[] a) {
Methods How many of the code fragments, inserted
NewQB independently at line 12, compile? MCQ 1 2 3 0 0 0 1

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");
}
Access {
Specifiers System.out.println("Man");
Constructors }}
Methods consider the code above & select the proper Man Dog Cat Cat Ant Dog Dog Man Cat
NewQB output from the options. MCQ Ant Man Ant compile error 0 0 1 0
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
Access int[] ar=new int[5]; them we
Specifiers for(i=0;i < ar.length;i++) A Sequence A Sequence need to
Constructors System.out.println(ar[i]); of 5 zero's of 5 one's will declare Mine
Methods } will be printed be printed IndexOutOfB class as
NewQB } MCQ like 0 0 0 0 0 like 1 1 1 1 1 oundes Error abstract 0 0 0 1
public class Q {
Access public static void main(String argv[]) { Compiler
Specifiers int anar[] = new int[] { 1, 2, 3 }; Error: anar is Compiler
Constructors System.out.println(anar[1]); referenced Error: size of
Methods } before it is array must be
NewQB } MCQ initialized 2 1 defined 0 1 0 0
Access
Specifiers
Constructors
Methods A constructor may return value including
NewQB class type MCQ true false 0 1
Consider the following code and choose the
correct option:
Access package aj; class S{ int roll =23;
Specifiers private S(){} }
Constructors package aj; class T
Methods { public static void main(String ar[]){ Compilation Compiles and Compiles and Compiles but
NewQB System.out.print(new S().roll);}} MCQ error display 0 display 23 no output 1 0 0 0

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() {
Access System.out.println("Hello123"); It is not
Specifiers } possible to
Constructors } declare a
Methods constructor Compilation Runs without
NewQB What is the output? MCQ Hellow as private Error any output 0 0 1 0
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 Runtime
NewQB What would be the output? MCQ error Exception 2500 50 0 0 1 0

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
Access static int i1; Compile time Static
Specifiers System.out.println(i1); error because variables are
Constructors } i has not Compilation class level
Methods } been and output of dependencies
NewQB What is the Output of the Program? MCQ initialized null . 0 0 0 1

public class MyAr {


public static void main(String argv[]) {
MyAr m = new MyAr();
m.amethod();
} Unresolved
public void amethod() { compilation
Access final int i1; problem: The
Specifiers System.out.println(i1); local variable
Constructors } i1 may not Compilation
Methods } have been and output of None of the
NewQB What is the Output of the Program? MCQ initialized null given options 0 1 0 0

public class c1 {
private c1()
{
System.out.println("Hello");
}
public static void main(String args[])
{
Access c1 o1=new c1(); It is not Can't create
Specifiers } possible to object
Constructors } declare a because
Methods constructor Compilation constructor is
NewQB What is the output? MCQ Hello private Error private 1 0 0 0
Access
Specifiers Which modifier indicates that the variable
Constructors might be modified asynchronously, so that all
Methods threads will get the correct value of the
NewQB variable. MCQ synchronized volatile transient default 0 1 0 0

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;

B(int a, int b, int c) {


super(a, b);
k = c;
}
void show(String msg) {
System.out.println(msg + k);
}
}
class Override {
public static void main(String args[]) {
B subOb = new B(3, 5, 7);
Access subOb.show("This is k: "); // this calls
Specifiers show() in B
Constructors subOb.show(); // this calls show() in A
Methods } This is j: 5 i This is i: 3 j This is i: 7 j This is k: 7 i
NewQB } What would be the ouput? MCQ and k: 3 7 and k: 5 7 and k: 3 5 and j: 3 7 0 0 0 1
Consider the following code and choose the
correct option:
Access class X { int x; X(int x){x=2;}}
Specifiers class Y extends X{ Y(){} void displayX(){
Constructors System.out.print(x);} Compiles and
Methods public static void main(String args[]){ Compiles and runs without Compiles and Compilation
NewQB new Y().displayX();}} MCQ display 2 any output display 0 error 0 0 0 1
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 Dog Cat Ant Ant Cat Dog none 0 1 0 0
What will be the result when you attempt to
compile this program?
public class Rand{
public static void main(String argv[]){
Access int iRand; A compile
Specifiers iRand = Math.random(); Compile time A random A random time error as
Constructors System.out.println(iRand); error referring number number random being
Methods } to a cast between 1 between 0 an undefined
NewQB } MCQ problem and 10 and 1 method 1 0 0 0
Annotations_ Choose the meta annotations. (Choose
NewQB THREE) MCA Override Retention Depricated Documented Target 0 0.333333 0 0.333333 0.333333
If no retention policy is specified for an
Annotations_ annotation, then the default policy of
NewQB __________ is used. MCQ method class source runtime 0 1 0 0
Select the variable which are in
Annotations_ java.lang.annotation.RetentionPolicy class. CONSTRUCT
NewQB (Choose THREE) MCA SOURCE METHOD RUNTIME OR CLASS 0.333333 0 0.333333 0 0.333333
Compile time
Information and
Annotations_ Select the Uses of annotations. (Choose For the Information deploytime Runtime Information
NewQB THREE) MCA Compiler for the JVM processing processing for the OS 0.333333 0 0.333333 0.333333 0

Annotations_ All annotation types should maually extend


NewQB the Annotation interface. State TRUE/FALSE MCQ true false 0 1
Annotations_ all the listed
NewQB Custom annotations can be created using MCQ @interface @inherit @include options 1 0 0 0
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 Compilation Compilation
25. a.y();; fails because The code An exception fails because fails because
Collections_u 26. } of an error in runs with no is thrown at of an error in of an error in
til_NewQB What is the result? MCQ line 25 output. runtime line 21 line 23. 1 0 0 0 0

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 + ", ");
} An exception
Collections_u } Compilation is thrown at
til_NewQB What is the result? MCQ A, B, C, B, C, A, fails. runtime. 0 1 0 0

Which statement is true about the following


program?
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class WhatISThis {
public static void main(String[] na){
List<StringBuilder> list=new
ArrayList<StringBuilder>();
list.add(new StringBuilder("B"));
list.add(new StringBuilder("A"));
list.add(new StringBuilder("C"));
Collections.sort(list,Collections.reverseOrder() The program The program The program
); will compile will compile will compile
System.out.println(list.subList(1,2)); and print the and print the and throw a The program
Collections_u } following following runtime will not
til_NewQB } MCQ output: [B] output: [B,A] exception compile 0 0 1 0
Consider the following code and choose the
correct option:
public static void before() {
Set set = new TreeSet();
set.add("2");
set.add(3);
set.add("1"); The before()
Iterator it = set.iterator(); method will
while (it.hasNext()) The before() The before() throw an The before()
Collections_u System.out.print(it.next() + " "); method will method will exception at method will
til_NewQB } MCQ print 1 2 print 1 2 3 runtime not compile 0 0 1 0
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_u System.out.println(st.nextElement()); Today is Today is none of the
til_NewQB }} MCQ Holiday Holiday Both listed options 0 1 0 0

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 + ", "); The code
Collections_u } Compilation runs with no
til_NewQB What is the result? MCQ 3, 2, 1, 1, 2, 3, fails. output. 0 0 1 0
Which collection class allows you to grow or
shrink its size and provides indexed access
to
Collections_u its elements, but its methods are not java.util.Hash java.util.Linke java.util.Array java.util.Vect
til_NewQB synchronized? MCQ Set dHashSet java.util.List List or 0 0 0 1 0

Collections_u int indexOf(Object o) - What does this method none of the


til_NewQB return if the element is not found in the List? MCQ null -1 listed options 0 1 0 0
What is the result of attempting to compile
and run the following code?
import java.util.Vector; import
java.util.LinkedList; public class Test1{ public
static void main(String[] args) { Integer int1 =
new Integer(10); Vector vec1 = new Vector();
LinkedList list = new LinkedList();
vec1.add(int1); list.add(int1);
if(vec1.equals(list))
System.out.println("equal"); else
System.out.println("not equal"); } } 1. The
code will fail to compile. 2. Runtime error due
to incompatible object comparison 3. Will run
Collections_u and print "equal". 4. Will run and print "not
til_NewQB equal". MCQ 1 2 3 4 0 0 1 0
Consider the following code and choose the
correct option:
class Test{
public static void main(String args[]){
Integer arr[]={3,4,3,2};
Set<Integer> s=new
TreeSet<Integer>(Arrays.asList(arr));
s.add(1); Compiles but
Collections_u for(Integer ele :s){ Compilation exception at
til_NewQB System.out.println(ele); } }} MCQ error prints 3,4,2,1, prints 1,2,3,4 runtime 0 0 1 0

Inorder to remove one element from the given


Treeset, place the appropriate line of code
public class Main {
public static void main(String[] args) {
TreeSet<Integer> tSet = new
TreeSet<Integer>();
System.out.println("Size of TreeSet : " +
tSet.size());
tSet.add(new Integer("1"));
tSet.add(new Integer("2"));
tSet.add(new Integer("3"));
System.out.println(tSet.size());
// remove the one element from the Treeset
System.out.println("Size of TreeSet after
removal : " + tSet.size()); tSet.clear(ne tSetdelete(ne tSet.remove(n
Collections_u } w w ew tSet.drop(new
til_NewQB } MCQ Integer("1")); Integer("1")); Integer("1")); Integer("1")); 0 0 1 0
Consider the code below & select the correct
ouput from the options:
public class Test{
public static void main(String[] args) {
String
[]colors={"orange","blue","red","green","ivory"}
;
Arrays.sort(colors);
int s1=Arrays.binarySearch(colors, "ivory");
Collections_u int s2=Arrays.binarySearch(colors, "silver");
til_NewQB System.out.println(s1+" "+s2); }} MCQ 2 -4 3 -5 2 -6 3 -4 0 0 1 0

Consider the following code and choose the


correct output:
class Test{
public static void main(String args[]){
TreeMap<Integer, String> hm=new
TreeMap<Integer, String>();
hm.put(2,"Two");
hm.put(4,"Four");
hm.put(1,"One");
hm.put(6,"Six");
hm.put(7,"Seven");
SortedMap<Integer, String>
sm=hm.subMap(2,7);
SortedMap<Integer,String> {2=Two,
sm2=sm.tailMap(4); 4=Four, {4=Four, {2=Two,
Collections_u System.out.print(sm2); 6=Six, 6=Six, {4=Four, 4=Four,
til_NewQB }} MCQ 7=Seven} 7=Seven} 6=Six} 6=Six} 0 0 1 0
Collections_u next() method of Scanner class will return
til_NewQB _________ MCQ Integer Long int String 0 0 0 1

Given:
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class MainClass {

public static void main(String[] a) {


String elements[] = { "A", "B", "C", "D",
"E" };
Set set = new
HashSet(Arrays.asList(elements));

elements = new String[] { "A", "B", "C",


"D" };
Set set2 = new
HashSet(Arrays.asList(elements));

System.out.println(set.equals(set2));
Collections_u } Compile time Runtime
til_NewQB } What is the result of given code? MCQ true false error Exception 0 1 0 0
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
Collections_u between timezones. A and B is A and D is A and C is B and D is
til_NewQB D) Vector class is not synchronized MCQ TRUE TRUE TRUE TRUE 0 0 1 0
Collections_u Which interface does java.util.Hashtable Java.util.Colle
til_NewQB implement? MCQ Java.util.Map Java.util.List Java.util.Table ction 1 0 0 0
Object get(Object key) - What does this
Collections_u method return if the key is not found in the none of the
til_NewQB Map? MCQ -1 null listed options 0 0 1 0

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);
Collections_u System.out.println(ss); [1,4,6,8] [1,8,6,4] [1,4,6,8,9] [1,4,6,8,9]
til_NewQB }} MCQ [4,6,8,9] [8,6,4,9] [4,6,8,9] [4,6,8] 0 0 1 0
A) Iterator does not allow to insert elements
during traversal
B) Iterator allows bidirectional navigation.
C) ListIterator allows insertion of elements
during traversal
Collections_u D) ListIterator does not support bidirectional A and B is A and D is A and C is B and D is
til_NewQB navigation MCQ TRUE TRUE TRUE TRUE 0 0 1 0
Collections_u static void sort(List list) method is part of Collection Collections ArrayList
til_NewQB ________ MCQ interface class Vector class class 0 1 0 0
Collections_u static int binarySearch(List list, Object key) is ArrayList Collection Collections
til_NewQB a method of __________ MCQ Vector class class interface class 0 0 0 1
Which collection class allows you to access
its elements by associating a key with an
Collections_u element's value, and provides java.util.Sorte java.util.Tree java.util.Tree java.util.Hash
til_NewQB synchronization? MCQ dMap Map Set table 0 0 0 1
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);
Collections_u }
til_NewQB } MCQ [1,3,2] [1,3,3,2] [1,3,2,1,3,2] [3,1,2] [3,1,1,2] 1 0 0 0 0

Given:
import java.util.*;

public class LetterASort{


public static void main(String[] args) {
ArrayList<String> strings = new
ArrayList<String>();
strings.add("aAaA");
strings.add("AaA");
strings.add("aAa");
strings.add("AAaa");
Collections.sort(strings);
for (String s : strings) { System.out.print(s + "
"); }
}
Collections_u } Compilation aAaA aAa AAaa AaA AaA AAaa
til_NewQB What is the result? MCQ fails. AAaa AaA aAa aAaA aAaA aAa 0 0 1 0
A) It is a good practice to store heterogenous
data in a TreeSet.
B) HashSet has default initial capacity (16)
and loadfactor(0.75)
C)HashSet does not maintain order of
Collections_u Insertion A and B is A and D is A and C is B and C is
til_NewQB D)TreeSet maintains order of Inserstion MCQ TRUE TRUE TRUE TRUE 0 0 0 1
TreeSet<String> s = new TreeSet<String>();
TreeSet<String> subs = new
TreeSet<String>();
s.add("a"); s.add("b"); s.add("c"); s.add("d");
s.add("e");

subs = (TreeSet)s.subSet("b", true, "d",


true);
s.add("g");
s.pollFirst();
s.pollFirst();
s.add("c2");
Collections_u System.out.println(s.size() +" "+ The size of s The size of s The size of The size of s The size of
til_NewQB subs.size()); MCA is 4 is 5 subs is 3 is 7 subs is 1 0 0.5 0.5 0 0
Consider the following code was executed on
June 01, 1983. What will be the output?
class Test{
public static void main(String args[]){
Date date=new Date();
SimpleDateFormat sd;
sd=new SimplpeDateFormat("E MMM dd
Collections_u yyyy"); Wed Jun 01 244 JUN 01 PST JUN 01 GMT JUN 01
til_NewQB System.out.print(sd.format(date));}} MCQ 1983 1983 1983 1983 1 0 0 0

Given:
public class Venus {
public static void main(String[] args) {
int [] x = {1,2,3};
int y[] = {4,5,6};
new Venus().go(x,y);
}
void go(int[]... z) {
for(int[] a : z)
System.out.print(a[0]);
Collections_u }
til_NewQB } What is the result? MCQ 123 12 14 1 0 0 1 0

You wish to store a small amount of data and


make it available for rapid access. You do not
have a need for the data to be sorted,
uniqueness is not an issue and the data will
remain fairly static Which data structure
might be most suitable for this requirement?

1) TreeSet
2) HashMap
Collections_u 3) LinkedList
til_NewQB 4) an array MCQ 1 2 3 4 0 0 0 1
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);
Collections_u ss.add(6);
til_NewQB System.out.print(ss);}} MCQ [2,3,7,5] [2,3,7,5,4,6] [2,3,4,5,6,7] [2,3,4,5,6] 0 0 0 1

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
Collections_u s.add(new Data(2)); compilation error at run
til_NewQB System.out.print(s.size());}} MCQ 3 5 error time 0 1 0 0

Consider the code below & select the correct


ouput from the options:
public class Test{
public static void main(String[] args) {
String num="";
Control z: for(int x=0;x<3;x++)
structures for(int y=0;y<2;y++){
wrapper if(x==1) break;
classes auto if(x==2 && y==1) break z;
boxing num=num+x+y; Compilation
NewQB }System.out.println(num);}} MCQ 0001 000120 00012021 error 0 1 0 0

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 } Compilation
NewQB What is the result? MCQ collie harrier fails. collie harrier 0 0 0 1
Consider the following code and choose the
correct output:
Control class Test{
structures public static void main(String args[]){
wrapper boolean flag=true;
classes auto if(flag=false){
boxing System.out.print("TRUE");}else{ compilation
NewQB System.out.print("FALSE");}}} MCQ true false error Compiles 0 1 0 0
Cosider the following code and choose the
Control correct option:
structures class Test{
wrapper public static void main(String args[])
classes auto { System.out.println(Integer.parseInt("21474 NumberForm
boxing 83648", 10)); Compilation 2.147483648 atException Compiles but
NewQB }} MCQ error E9 at run time no output 0 0 1 0

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 } Compilation
NewQB What is the result? MCQ harrier shepherd retriever fails. 0 0 0 1

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 21 22 23 24 0 0 1 0 0
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 3 <= r <= 10 2<= r <= 10 3 <= r <= 9 1 0 0 0
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 none of the
NewQB output from the options. MCQ R.T.Ponting C.H.Gayle Compile error listed options 0 0 1 0

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 24 234 246 0 1 0 0
Consider the following code and choose the
correct output:
Control class Test{
structures public static void main(String args[]){
wrapper int a=5;
classes auto if(a=3){
boxing System.out.print("Three");}else{ Compilation Compiles but
NewQB System.out.print("Five");}}} MCQ error Three Five no output 1 0 0 0

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 82 91 92 0 1 0 0
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 } If a is true If a is true If a is false If a is false
wrapper } and b is false and b is true and b is false and b is true
classes auto } then the then the then the then the
boxing output is output is "A output is output is
NewQB What would be the result? MCQ "notB" && B" "ELSE" "ELSE" 0 0 0 1

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)
Control {
structures case p: n = n + 1;
wrapper case q: n = n + 2;
classes auto case r: n = n + 3;
boxing default: n = n + 4; Compilation
NewQB } MCQ 14 28 Error 10 Runtime Error 0 0 1 0 0

public class While


{
public void loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
{
System.out.print("x plus one is " + (x
Control + 1)); /* Line 8 */
structures }
wrapper } There are There are
classes auto } There is a syntax errors syntax errors There is a
boxing syntax error on lines 1 on lines 1, 6, syntax error
NewQB Which statement is true? MCQ on line 1 and 6 and 8 on line 6 0 0 0 1
Which of the following loop bodies DOES
compute the product from 1 to 10 like (1 * 2 *
3*4*5*
Control 6 * 7 * 8 * 9 * 10)?
structures int s = 1;
wrapper for (int i = 1; i <= 10; i++)
classes auto {
boxing <What to put here?> Compilation
NewQB } MCQ s += i * i; s++; s = s + s * i; s *= i; error 0 0 0 1 0
Control
structures
wrapper Character
classes auto Double has a has a String is the
boxing Which of the following statements are true String is a compareTo() intValue() Byte extends wrapper class
NewQB regarding wrapper classes? (Choose TWO) MCA wrapper class method method Number of char 0 0.5 0 0.5 0

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 granite atom granite atom granite
NewQB What is the result? MCQ fails. granite granite atom granite 0 0 0 1

What are the thing to be placed to complete


the code?
class Wrap {
public static void main(String args[]) {

_______________ iOb = ___________


Integer(100);

Control int i = iOb.intValue();


structures
wrapper System.out.println(i + " " + iOb); //
classes auto displays 100 100
boxing }
NewQB } MCQ int, int Integer, new Integer, int int, Integer 0 1 0 0
public class SwitchTest
{
public static void main(String[] args)
{
System.out.println("value =" +
switchIt(4));
}
public static int switchIt(int x)
{
int j = 1;
switch (x)
{
case 1: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
Control default: j++;
structures }
wrapper return j + x;
classes auto }
boxing }
NewQB What will be the output of the program? MCQ value = 8 value = 2 value = 4 value = 6 1 0 0 0

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 } Compilation
NewQB What is the result? MCQ hi hi hi world world world fails. 0 0 0 1
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; Compiles but
boxing System.out.println(ans); compilation error at run
NewQB }} MCQ 40 46 error time 1 0 0 0
11. double input = 314159.26;
12. NumberFormat nf =
Control NumberFormat.getInstance(Locale.ITALIAN);
structures 13. String b;
wrapper 14. //insert code here
classes auto b= b= b= b=
boxing Which code, inserted at line 14, sets the nf.parse( inpu nf.format( inp nf.equals( inp nf.parseObjec
NewQB value of b to 314.159,26? MCQ t ); ut ); ut ); t( input ); 0 1 0 0
Consider the following code and choose the
correct option:
class Test{
public static void main(String ar[]){
TreeMap<Integer,String> tree = new
TreeMap<Integer,String>();
tree.put(1, "one");
tree.put(2, "two");
tree.put(3, "three");
Control tree.put(4,"Four");
structures System.out.println(tree.higherKey(2));
wrapper System.out.println(tree.ceilingKey(2));
classes auto System.out.println(tree.floorKey(1));
boxing System.out.println(tree.lowerKey(1));
NewQB }} MCQ 3 2 1 null 3211 2211 4211 1 0 0 0
Control Consider the following code and choose the
structures correct option:
wrapper class Test{
classes auto public static void main(String args[]){ Compiles but
boxing Long data=23; Compilation error at run None of the
NewQB System.out.println(data); }} MCQ 23 error time listed options 0 1 0 0
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 No, Runtime
NewQB would be the result? MCQ error error Yes, 10, 100 Yes, 100, 100 0 0 0 1
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 true false 1 0 0 1 0
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 2 4 1 0 0 0 1

what will be the result of attempting to


compile and run the following class? The code will
Public class IFTest{ fail to compile
public static void main(String[] args){ because the
int i=10; compiler will
Control if(i==10) The code will not be able to The code will The code will The code will
structures if(i<10) fail to compile determine compile compile compile
wrapper System.out.println("a"); because the which if correctly and correctly and correctly,but
classes auto else syntax of the statement the display the display the will not
boxing System.out.println("b"); if statement else clause letter a,when letter b,when display any
NewQB }} MCQ is incorrect belongs to run run output 0 0 0 1 0
What is the output of the following code :
class try1{
public static void main(String[] args) {
Control System.out.println("good");
structures while(false){
wrapper System.out.println("morning");
classes auto }
boxing } good morning
NewQB } MCQ good morning …. compiler error runtime error 0 0 1 0
Consider the following code and choose the
correct output:
class Test{
public static void main(String args[]){
Control int num=3; switch(num){
structures case 1: case 3: case 4: {
wrapper System.out.println("bat man"); }
classes auto case 2: case 5: {
boxing System.out.println("spider man"); } Compilation bat man
NewQB break; } }} MCQ bat man error spider man spider man 0 0 1 0
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 Compilation
NewQB following code? MCQ 23 32 25 Error Runtine Error 0 0 1 0 0

What will be the output of following code?

TreeSet map = new TreeSet();


map.add("one");
map.add("two");
map.add("three");
map.add("four");
Control map.add("one");
structures Iterator it = map.iterator();
wrapper while (it.hasNext() )
classes auto {
boxing System.out.print( it.next() + " " ); one two three four three two four one three one two three
NewQB } MCQ four one two four one 0 0 1 0

public class Test {


public static void main(String [] args) {
int x = 5;
boolean b1 = true;
boolean b2 = false;

if ((x == 4) && !b2 )


System.out.print("1 ");
Control System.out.print("2 ");
structures if ((b2 = true) && b1 )
wrapper System.out.print("3 ");
classes auto }
boxing }
NewQB What is the result? MCQ 2 3 23 123 0 0 1 0
Control
structures
wrapper
classes auto HashTable is ArrayList is a LinkedList is Stack is a
boxing a sub class sub class of a subclass of subclass of
NewQB Which of these statements are true? MCA of Dictionary Vector ArrayList Vector 0.5 0 0 0.5
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);
subs = (TreeSet)s.subSet(608, true, 611,
Control true);
structures subs.add(629);
wrapper System.out.println(s + " " + subs); [608, 610,
classes auto } [608, 610, An exception 612, 629]
boxing } Compilation 612, 629] is thrown at [608, 610,
NewQB What is the result? MCQ fails. [608, 610] runtime. 629] 0 0 1 0
What is the output :
class try1{
public static void main(String[] args) {
int x=1;
Control if(x--)
structures System.out.println("good");
wrapper else
classes auto System.out.println("bad");
boxing }
NewQB } MCQ good bad compile error run time error 0 0 1 0

Consider the following code and choose the


correct output:
class Test{
public static void main(String args[]){
int num='b'; switch(num){
Control default :{
structures System.out.print("default");}
wrapper case 100 : case 'b' : case 'c' : {
classes auto System.out.println("brownie"); break;}
boxing case 200: case 'e': { default compilation
NewQB System.out.println("pastry"); }break; } }} MCQ brownie brownie error default 1 0 0 0

Given:
int a = 5;
int b = 5;
int c = 5;
if (a > 3)
if (b > 4)
if (c > 5)
c += 1;
else
Control c += 2;
structures else
wrapper c += 3;
classes auto c += 4;
boxing What is the value of variable c after executing
NewQB the following code? MCQ 3 5 7 9 11 0 0 0 0 1
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."); An exception pi is bigger
boxing } Compilation pi is bigger occurs at than 3. Have
NewQB What is the result? MCQ fails. than 3. runtime. a nice day. 1 0 0 0

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 0001 000120 00012021 0 0 1 0

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
classes auto code prints:
boxing
NewQB 12345678 MCQ count < 9 count+1 <= 8 count < 8 count != 8 1 0 0 0
What will be the output of the program?

public class Switch2


{
final static short x = 2;
public static int y = 0;
public static void main(String [] args)
{
for (int z=0; z < 3; z++)
{
switch (z)
{
case y: System.out.print("0 "); /*
Line 11 */
case x-1: System.out.print("1 "); /*
Line 12 */
Control case x: System.out.print("2 "); /*
structures Line 13 */
wrapper }
classes auto } Compilation
boxing } Compilation fails at line
NewQB } MCQ 012 012122 fails at line 11 12. 0 0 1 0
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 5,5 6,5 6,6 0 1 0 0

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 } none of the
NewQB } MCQ success runtime error compiler error listed options 0 0 1 0
Consider the following code and choose the
correct output:
public class Test{
public static void main(String[] args) {
int x = 0;
int y = 10;
do {
Control y--;
structures ++x;
wrapper } while (x < 5);
classes auto System.out.print(x + "," + y);
boxing }
NewQB } MCQ 5,6 5,5 6,5 6,6 0 1 0 0
Consider the following code and choose the
Control correct option:
structures class Test{
wrapper public static void main(String args[]){
classes auto int l=7; Compiles but
boxing Long L = (Long)l; Compilation error at run None of the
NewQB System.out.println(L); }} MCQ 7 error time listed options 0 1 0 0

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 tall short short very short average 0 1 0 0 0
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"; Compiles but
boxing int number = Integer.decode(hexa); Compilation error at run
NewQB System.out.println(number); }} MCQ error 1515 255 time 0 0 1 0
Consider the following code and choose the
correct option:
int i = l, j = -1;
switch (i)
Control {
structures case 0, 1: j = 1;
wrapper case 2: j = 2;
classes auto default: j = 0;
boxing } Compilation
NewQB System.out.println("j = " + j); MCQ j = -1 j=0 j=1 fails 0 0 0 1
Control
structures
wrapper
classes auto Person[] p = Person p[][] =
boxing Which of the following statements about new new
NewQB arrays is syntactically wrong? MCQ Person[5]; Person p[5]; Person[] p []; Person[2][]; 0 1 0 0

What will be the output of following code?

import java.util.*;
class I
{
public static void main (String[] args)
{
Object i = new ArrayList().iterator();
System.out.print((i instanceof List)+",");
Control System.out.print((i instanceof Iterator)
structures +",");
wrapper System.out.print(i instanceof
classes auto ListIterator);
boxing } Prints: false, Prints: false, Prints: false, Prints: false,
NewQB } MCQ false, false false, true true, false true, true 0 0 1 0

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"); An exception
boxing test("to"); Compilation is thrown at
NewQB What is the result? MCQ r, t, t, r, e, o, fails. runtime. 0 0 1 0
What will be the output of the program?
Control int x = 3;
structures int y = 1;
wrapper if (x = y) /* Line 3 */
classes auto { The code
boxing System.out.println("x =" + x); Compilation runs with no
NewQB } MCQ x=1 x=3 fails. output. 0 0 1 0
import java.util.SortedSet;
import java.util.TreeSet;

public class Main {

public static void main(String[] args) {


TreeSet<String> tSet = new
TreeSet<String>();
tSet.add("1");
tSet.add("2");
tSet.add("3");
tSet.add("4");
tSet.add("5");
Control SortedSet sortedSet =_____________("3");
structures System.out.println("Head Set Contains : "
wrapper + sortedSet);
classes auto }
boxing } What is the missing method in the code to
NewQB get the head set of the tree set? MCQ tSet.headSet tset.headset headSet HeadSet 1 0 0 0

Consider the following code and choose the


correct output:
class Test{
public static void main(String args[]){
int num=3; switch(num){
default :{
Control System.out.print("default");}
structures case 1: case 3: case 4: {
wrapper System.out.println("apple"); break;}
classes auto case 2: case 5: {
boxing System.out.println("black berry"); } compilation
NewQB break; } }} MCQ apple default apple error default 1 0 0 0
Consider the following code and choose the
correct option:
Control class Test{
structures public static void main(String args[]){
wrapper Long L = null; long l = L;
classes auto System.out.println(L); Compiles but
boxing System.out.println(l); Compilation error at run
NewQB }} MCQ null 0 error time 0 null 0 0 1 0

What does the following code fragment write


to the monitor?

int sum = 21;


if ( sum != 20 )
System.out.print("You win ");
Control else
structures System.out.print("You lose ");
wrapper
classes auto System.out.println("the prize.");
boxing You win the You lose the
NewQB What does the code fragment prints? MCQ prize prize. You win You lose 1 0 0 0
Changes
made in the
Control Set view
structures returned by The Map
wrapper The return keySet() will interface All Map
classes auto type of the be reflected extends the All keys in a implementati
boxing Which statements are true about maps? values() in the original Collection map are ons keep the
NewQB (Choose TWO) MCA method is set map interface unique keys sorted 0 0.5 0 0.5 0
Control
structures Which collection implementation is suitable
wrapper for maintaining an ordered sequence of
classes auto objects,when objects are frequently inserted
boxing in and removed from the middle of the
NewQB sequence? MCQ TreeMap HashSet Vector LinkedList ArrayList 0 0 0 1 0
OutputStrea To write
m is the characters to
abstract an
Control superclass of Subclasses outputstream, To write an
structures all classes of the class you have to object to a
wrapper that represent Reader are make use of file, you use
classes auto an used to read the class the class
boxing outputstream character CharacterOut ObjectFileWri
NewQB Choose TWO correct options: MCA of bytes. streams. putStream. ter 0.5 0.5 0 0

What is the output :


class One{
public static void main(String[] args) {
int a=100;
if(a>10)
Control System.out.println("M.S.Dhoni");
structures else if(a>20)
wrapper System.out.println("Sachin");
classes auto else if(a>30) M.S.Dhoni
boxing System.out.println("Virat Kohli");} Sachin Virat
NewQB } MCQ M.S.Dhoni Kohli Virat Kohli all of these 1 0 0 0
A continue If a variable of
statement type int
Control doesn’t overflows
structures transfer during the
wrapper control to the An overflow execution of
classes auto test error can only A loop may a loop, it will
boxing Which of the following statements is TRUE statement of occur in a have multiple cause an
NewQB regarding a Java loop? MCQ the for loop loop exit points exception 0 0 1 0
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 2 and 4 3 and 5 4 and 6 1 0 0 0

When an
exception When no
occurs then a exception
part of try occurs then
block will complete try
Used to execute one finally block block and
release the appropriate will never finally block
resources catch block execute when will execute
Exception_ha which are Writing finally and finally no but no catch
ndling_NewQ Which are true with respect to finally block? obtained in block is block will be exceptions block will
B (Choose THREE) MCA try block. optional. executed. are there. execute. 0.25 0.25 0.25 0 0.25

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
Exception_ha } defined for defined for the values 0 compile but
ndling_NewQ } the Thread the Thread to 9 are no output at
B } MCQ class class printed out runtime 0 0 0 1

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 } An exception
ndling_NewQ What is the result when method testIfA is is thrown at
B invoked? MCQ true Not true runtime. none 1 0 0 0
A thread will
resume Both wait()
The wait() execution as The notify() and notify()
Deadlock will method is soon as its method is must be
Exception_ha not occur if overloaded to sleep overloaded to called from a
ndling_NewQ Which of the following statements are true? wait()/notify() accept a duration accept a synchronized
B (Choose TWO) MCA is used duration expires. duration context. 0 0.33 0.33 0 0.33

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 Hello
System.out.println("Done with try world, then
block "); will print that The program The program
} a will print Hello will print Hello
finally RuntimeExce world, then world, then
{ ption has will print that will print
System.out.println("Finally executing occurred, a Finally
"); then will print RuntimeExce executing,
} Done with try ption has then will print
} block, and occurred, and that a
Exception_ha } The program then will print then will print RuntimeExce
ndling_NewQ which answer most closely indicates the will not Finally Finally ption has
B behavior of the program? MCQ compile. executing. executing. occurred. 0 0 0 1
If a method is capable of causing an
exception that it does not handle, it must
Exception_ha specify this behavior using throws so that
ndling_NewQ callers of the method can guard themselves
B against such Exception MCQ false true 0 1
A) Checked Exception must be explicity
caught or propagated to the calling method
B) If runtime system can not find an
Exception_ha appropriate method to handle the exception,
ndling_NewQ then the runtime system terminates and uses Only A is Only B is Bothe A and Both A and B
B the default exception handler. MCQ TRUE TRUE B is TRUE is FALSE 0 0 1 0
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
Exception_ha System.out.println("after "); hello throwit RuntimeExce
ndling_NewQ } caught finally hello throwit ption caught Compilation
B } MCQ after caught after fails 1 0 0 0

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();
Exception_ha t2.start(); Cannot
ndling_NewQ } Compilation determine prints 12 12
B } What is the output? MCQ DeadLock Error output. 12 12 0 0 0 1
What is wrong with the following code?

Class MyException extends Exception{}


public class Test{
public void foo() {
try {
bar(); Since the
} finally { method foo()
baz(); does not
} catch(MyException e) {} catch the
} exception
public void bar() throws MyException { generated by
throw new MyException(); the method A try block
} baz(),it must cannot be A finally
public void baz() throws RuntimeException { declare the followed by block must
Exception_ha throw new RuntimeException(); RuntimeExce both a catch An empty A catch block always follow
ndling_NewQ } ption in a and a finally catch block cannot follow one or more
B } MCQ throws clause block is not allowed a finally block catch blocks 0 0 0 1 0

Consider the following code and choose the


correct option:
class Test{
static void test() throws RuntimeException {
try { System.out.print("test ");
throw new RuntimeException();
} catch (Exception ex)
{ System.out.print("exception "); }
} public static void main(String[] args) {
Exception_ha try { test(); } catch (RuntimeException ex) test test
ndling_NewQ { System.out.print("runtime "); } test runtime exception exception
B System.out.print("end"); } } MCQ test end end runtime end end 0 0 0 1

A method
declaring that
it throws a
If an An overriding certain Finally blocks
exception is method must exception are executed
not caught in declare that it The main() class may if,an
a method,the throws the method of a throw exception
method will same program can instances of gets thrown
terminate and exception declare that it any subclass while inside
Exception_ha normal classes as throws of that the
ndling_NewQ execution will the method it checked exception correspondin
B Choose TWO correct options: MCA resume overrides exception class g try block 0 0 0.5 0.5 0
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 2, 3, 4 and 5 1, 4, 5 and 6 2, 4, 5 and 6 0 0 1 0
class X implements Runnable
{
public static void main(String args[])
{
/* Missing code? */
} X run = new
public void run() {} Thread t = X(); Thread t
Exception_ha } Thread t = new = new Thread t =
ndling_NewQ Which of the following line of code is suitable new Thread(X); Thread(run); new Thread();
B to start a thread ? MCQ Thread(X); t.start(); t.start(); x.run(); 0 0 1 0

Given:
class X { public void foo()
{ System.out.print("X "); } }

public class SubB extends X {


public void foo() throws RuntimeException {
super.foo();
if (true) throw new RuntimeException();
System.out.print("B ");
}
public static void main(String[] args) {
new SubB().foo(); No output, X, followed by
Exception_ha } and an an Exception,
ndling_NewQ } X, followed by Exception is followed by
B What is the result? MCQ an Exception. thrown. B. none 1 0 0 0

What will the output of following code?

try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic
Exception_ha Exception");
ndling_NewQ } compilation ArithmeticEx
B System.out.println("finished"); MCQ finished Exception fails ception 0 0 1 0
Exception_ha
ndling_NewQ
B Which of the following methods are static? MCA start() join() yield() sleep() 0 0 0.5 0.5
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
Exception_ha change their which this because they defined inside
ndling_NewQ Which of the following statements regarding implementati method is are defined at the same
B static methods are correct? (2 answers) MCA on. defined. class-level. class. 0 0.5 0 0.5

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
Exception_ha }catch(NullPointerException e) RuntimeExce
ndling_NewQ { System.out.println("caught");} ption thrown Compilation
B finally{ System.out.println("exit");}}}} MCQ caught exit exit at run time fails 0 0 1 0

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
Exception_ha }} occurred
ndling_NewQ consider the code above & select the proper Exception RuntimeExce RuntimeExce does not
B output from the options. MCQ occurred ption ption compile 0 0 0 1

Which three of the following are methods of


the Object class?

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 2, 4, 5 1, 2, 6 2, 3, 4 0 0 1 0
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
Exception_ha B. IllegalStateException
ndling_NewQ C. NumberFormatException ClassCastEx NumberForm IllegalStateEx IllegalArgume
B D. IllegalArgumentException MCA ception atException ception ntException 0 0.5 0 0.5

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 One Catch One Two
B }} MCQ Catch Finally One Catch Finally Catch 0 0 1 0

Which digit,and in what order,will be printed


when the following program is run?

Public class MyClass {


public static void main(String[] args) {
int k=0;
try {
int i=5/k;
}
catch(ArithmeticException e) {
System.out.println("1");
}
catch(RuntimeException e) {
System.out.println("2");
return;
}
catch(Exception e) {
System.out.println("3");
}
finally{
System.out.println("4");
} The program The program The program The program
Exception_ha System.out.println("5"); The program will only print will only print will only print will only print
ndling_NewQ } will only print 1 and 4 in 1,2 and 4 in 1 ,4 and 5 in 1,2,4 and 5 in
B } MCQ 5 order order order order 0 0 0 1 0
We cannot
class Trial{ have a try
public static void main(String[] args){ We cannot block block
Exception_ha try{ have a try without a
ndling_NewQ System.out.println("Java is portable"); Java is block without catch / finally Nothing is
B }}} MCQ portable a catch block block diaplayed 0 0 1 0
class Animal { public String noise() { return
"peep"; } }
class Dog extends Animal {
public String noise() { return "bark"; }
}
class Cat extends Animal {
public String noise() { return "meow"; }
}
class try1{
public static void main(String[] args){
Animal animal = new Dog();
Cat cat = (Cat)animal;
System.out.println(cat.noise());
Exception_ha }} An exception
ndling_NewQ consider the code above & select the proper Compilation is thrown at
B output from the options. MCQ bark meow fails runtime. peep 0 0 0 1 0

Given:
class X implements Runnable
{
public static void main(String args[])
{
/* Some code */
} X run = new
public void run() {} X(); Thread t Thread t =
Exception_ha } = new Thread t = Thread t = new
ndling_NewQ Which of the following line of code is suitable Thread(run); new new Thread(); Thread(X);
B to start a thread ? MCQ t.start(); Thread(X); x.run(); t.start(); 1 0 0 0
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
Exception_ha cannot be the with the sleeps, it
ndling_NewQ synchronized nonsynchroni synchronized releases its
B Which statement is true? MCQ . zed code. keyword. locks 0 1 0 0

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();
Exception_ha }catch(Exception e){ } Compiles but
ndling_NewQ catch(RuntimeException re){} Compiles and Compilation exception at
B finally{System.out.println("exit");}}} MCQ exit no output fails runtime 0 0 1 0
Given:
public class ExceptionTest
{
class TestException extends Exception {}
public void runTest() throws TestException
{}
public void test() /* Line X */
{
runTest();
}
Exception_ha } throws
ndling_NewQ At Line X, which code is necessary to make No code is throws throw RuntimeExce
B the code compile? MCQ necessary Exception Exception ption 0 1 0 0
Implement Implement Extend Implement
java.lang.Run Extend java.lang.Thre java.lang.Run java.lang.Thre
nable and java.lang.Thre ad and nable and ad and
Exception_ha implement ad and implement override the implement
ndling_NewQ Which two can be used to create a new the run() override the the start() start() the run()
B Thread? MCA method. run() method. method. method. method. 0.5 0.5 0 0 0

Except in
An Error that case of VM
might be shutdown, if a
Multiple thrown in a try block
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 that method, g finally block
Exception_ha least one of exception or be handled will always
ndling_NewQ correspondin more than within that start to
B Choose the correct option: MCQ g catch block once. method. execute. 0 0 0 1

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_ha }} Exception
ndling_NewQ consider the code above & select the proper Arithmetic Runtime Runtime compilation
B output from the options. MCQ Exception Exception Exception error 1 0 0 0
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 } Compilation finally
B What is the result? MCQ null fails. exception finally 0 0 1 0

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. } Compilation Compilation Compilation
ndling_NewQ What is the result when the second program 5 followed by fails with an fails with an fails with an
B is run? (Choose all that apply) MCA 567 an exception error on line 7 error on line 8 error on line 9 0 0 0 0.5 0.5
Consider the following code:

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: Code output: Start Hello
Exception_ha FileNotFoundException are both subclasses Start Hello Start Hello world Catch
ndling_NewQ of IOException. If this block of code is pasted The code will world File Not world End of Here File not
B in a method, choose the best option. MCQ not compile. Found file exception. found. 1 0 0 0
Any
Any statement
catch(X x) statement that can
can catch that can throw an
subclasses of The Error throw an Exception
Exception_ha X where X is class is a Error must be must be
ndling_NewQ a subclass of RuntimeExce enclosed in a enclosed in a
B Which of the following statements is true? MCQ Exception. ption. try block. try block. 1 0 0 0
Consider the following code and choose the
Exception_ha correct option:
ndling_NewQ int array[] = new int[10]; compiles does not none of the
B array[-1] = 0; MCQ successfully compile runtime error listed options 0 0 1 0
What will be the output of the program?

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
Exception_ha System.out.println("after "); RuntimeExce hello throwit
ndling_NewQ } hello throwit Compilation ption caught caught finally
B } MCQ caught fails after after 0 0 0 1
Exception_ha What is the keyword to use when the access
ndling_NewQ of a method has to be restricted to only one
B thread at a time MCQ volatile synchronized final private 0 1 0 0
Consider the following code and choose the
correct option:
class Test{
public static void parse(String str) {
try { int num = Integer.parseInt(str);
} catch (NumberFormatException nfe) {
num = 0; } finally NumberForm
Exception_ha { System.out.println(num); atException ParseExcepti
ndling_NewQ } } public static void main(String[] args) { thrown at Compilation on thrown at
B parse("one"); } MCQ runtime fails runtime 0 0 1 0

public static void parse(String str) {


try {
float f = Float.parseFloat(str);
} catch (NumberFormatException nfe) {
f = 0;
} finally { A
System.out.println(f); A NumberForm
} ParseExcepti atException
} on is thrown is thrown by
Exception_ha public static void main(String[] args) { by the parse the parse
ndling_NewQ parse("invalid"); Compilation method at method at
B } MCQ fails runtime. runtime. 0 1 0 0
Given the following program,which statements
are true? (Choose TWO)
Public class Exception {
public static void main(String[] args) { If run with one
try { If run with one arguments,th
if(args.length == 0) return; If run with no If run with no The program arguments,th e program will
System.out.println(args[0]); arguments,th arguments,th will throw an e program will print the given
Exception_ha }finally { e program will e program will ArrayIndexOu simply print argument
ndling_NewQ System.out.println("The end"); produce no produce "The tOfBoundsEx the given followed by
B }}} MCA output end" ception argument "The end" 0 0.5 0 0 0.5
Which can appropriately be thrown by a
Exception_ha programmer using Java SE technology to
ndling_NewQ create ClassCastEx NullPointerEx NoClassDefF NumberForm
B a desktop application? MCQ ception ception oundError atException 0 0 0 1
Exception_ha ArrayIndexOu
ndling_NewQ Which of the following is a checked Arithmetic NullPointerEx tOfBoundsEx
B exception? MCQ Exception IOException ception ception 0 1 0 0

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) Compilation Compilation
Exception_ha { System.out.println("Exception"); } fails because fails because
ndling_NewQ 22. } A,B,Exceptio of an error in of an error in
B What is the result? MCQ Exception n line 20. line 14. 0 0 0 1
The notify()
The notifyAll() The notify() method
method must To call method is causes a
be called sleep(), a defined in thread to
Exception_ha from a thread must class immediately
ndling_NewQ synchronized own the lock java.lang.Thre release its
B Which statement is true? MCQ context on the object ad locks. 1 0 0 0
class Trial{
public static void main(String[] args){
try{
System.out.println("Try Block");
}
finally{
Exception_ha System.out.println("Finally Block");
ndling_NewQ } Try Block Finally Block
B }} MCQ Try Block Finally Block Finally Block Try Block 0 1 0 0
consider the code & choose the correct
output:
class Threads2 implements Runnable {

public void run() {


System.out.println("run.");
throw new RuntimeException("Problem");
}
public static void main(String[] args) {
Thread t = new Thread(new Threads2()); End of End of
t.start(); run method. method. run.
Exception_ha System.out.println("End of method."); java.lang.Run java.lang.Run java.lang.Run java.lang.Run
ndling_NewQ } timeExceptio timeExceptio timeExceptio timeExceptio
B } MCQ n: Problem n: Problem n: Problem n: Problem 0 0 0 1
Exception_ha
ndling_NewQ The exceptions for which the compiler doesn’t Checked Unchecked
B enforce the handle or declare rule MCQ exceptions exceptions Exception all of these 0 1 0 0

Consider the code below & select the correct


ouput from the options:
public class Test{
Integer i;
int x;
Test(int y){
x=i+y;
System.out.println(x);
}
Exception_ha public static void main(String[] args) { Compiles but
ndling_NewQ new Test(new Integer(5)); Compilation error at run
B }} MCQ 5 error time 0 0 1 0

Given:
public class TestSeven extends Thread {
private static int x;
public synchronized void doThings() {
int current = x;
current++;
x = current; Declaring the
} Synchronizin doThings()
public void run() { g the run() method as
doThings(); method would static would
Exception_ha } make the make the An exception
ndling_NewQ } Compilation class class is thrown at
B Which statement is true? MCQ fails. thread-safe. thread-safe. runtime. 0 0 1 0

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();
Exception_ha }catch(NullPointerException e) Compiles but
ndling_NewQ { System.out.println("caught");} Compilation exception at
B System.out.println("exit");}}} MCQ caught exit exit fails runtime 0 0 0 1
An object will
not be
garbage
An object is collected as
deleted as The finalize() long as it
soon as there The finilize() method will possible for a The garbage
are no more method will never be live thread to collector will
Garbage_Coll Which statements describe guaranteed references eventually be called more access it use a mark
ection_NewQ behaviour of the garbage collection and that denote called on than once on through a and sweep
B finalization mechanisms? (Choose TWO) MCA the object every object an object reference. algorithm 0 0 0.5 0.5 0

Which statement is true?


A. A class's finalize() method CANNOT be
invoked explicitly.
B. super.finalize() is called implicitly by any
overriding finalize() method.
C. The finalize() method for a given object is
called no more than once by the garbage
collector.
D. The order in which finalize() is called on
Garbage_Coll two objects is based on the order in which the
ection_NewQ two
B objects became finalizable. MCQ A B C D 0 0 1 0
Only the
garbage
collection
Garbage_Coll system can
ection_NewQ Which of the following allows a programmer to Runtime.getR destroy an
B destroy an object x? MCQ x.delete() x.finalize() untime().gc() object. 0 0 0 1

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
B eligible for garbage collection? MCQ 1 2 3 0 0 1 0
Given :
public class MainOne {
public static void main(String args[]) {
String str = "this is java";
System.out.println(removeChar(str,'s'));
}

public static String removeChar(String s,


char c) {
String r = "";
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != c)
r += s.charAt(i);
}
Garbage_Coll return r;
ection_NewQ } none of the
B } What would be the result? MCQ This is java Thi is java This i java Thi i java listed options 0 0 0 1 0
Call
Set all System.gc()
references to passing in a
the object to reference to Garbage
Garbage_Coll new the object to collection
ection_NewQ How can you force garbage collection of an values(null, be garbage Call Call cannot be
B object? MCQ for example). collected System.gc() Runtime.gc(). forced 0 0 0 0 1

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
B eligible for garbage collection? MCQ 1 2 3 0 1 0 0
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_Abst Class_1 o11 = new Class_1(); From F1
ract o11.f1(); function in Create an
Classes_New } Class_1 Compile time object for
QB } MCQ Class error Interface only Runtime Error 0 1 0 0

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_Abst B b= new B(); This is a final
ract b.meth(); method illegal Some
Classes_New } This is a final Some error Compilation error
QB }What would be the result? MCQ method illegal message error message 0 0 1 0
Which Man class properly represents the
relationship "Man has a best friend who is a
Inheritance_In Dog"?
terfaces_Abst A)class Man extends Dog { }
ract B)class Man implements Dog { }
Classes_New C)class Man { private BestFriend dog; }
QB D)class Man { private Dog bestFriend; } MCQ A B C D 0 0 0 1
What will be the output of the program?

class SuperClass
{
public Integer getLength()
{
return new Integer(4);
}
}

public class SubClass extends SuperClass


{
public Long getLength()
{
return new Long(5);
}

public static void main(String[] args)


{
SuperClass sp = new SuperClass();
SubClass sb = new SubClass();
Inheritance_In System.out.println(
terfaces_Abst sp.getLength().toString() + "," +
ract sub.getLength().toString() );
Classes_New } Compilation
QB } MCQ 4, 4 4, 5 5, 4 fails 0 0 0 1

Consider the code below & select the correct


ouput from the options:
abstract class Ab{ public int getN(){return 0;}}
class Bc extends Ab{ public int getN(){return
7;}}
class Cd extends Bc { public int getN(){return
47;}}
class Test{
public static void main(String[] args) {
Inheritance_In Cd cd=new Cd();
terfaces_Abst Bc bc=new Cd();
ract Ab ab=new Cd();
Classes_New System.out.println(cd.getN()+" "+ Compilation
QB bc.getN()+" "+ab.getN()); }} MCQ 000 47 7 0 error 47 47 47 0 0 0 1
interface A{}
class B implements A{}
class C extends B{}
public class Test extends C{
public static void main(String[] args) {
Inheritance_In C c=new C();
terfaces_Abst /* Line6 */}}
ract
Classes_New Which code, inserted at line 6, will cause a
QB java.lang.ClassCastException? MCQ B b=c; A a2=(B)c; C c2=(C)(B)c; A a1=(Test)c; 0 0 0 1
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 The code will
return y; } fail to compile
} because the
class B extends A{ max() method
int max(int x, int y) { return super.max(y, x) - in B passes The code will
10; } the fail to compile
Inheritance_In } arguments in because a
terfaces_Abst class C extends B { the call call to a The code will The code will
ract int max(int x, int y) { return super.max(x+10, super.max(y, max() method compile and compile and
Classes_New y+10); } x) in the is print 23, print 29,
QB } MCQ wrong order. ambiguous. when run. when run. 0 0 0 1
The concept of multiple inheritance is
implemented in Java by

Inheritance_In (A) extending two or more classes


terfaces_Abst (B) extending one class and implementing
ract one or more interfaces
Classes_New (C) implementing two or more interfaces
QB (D) all of these MCQ (A) (A) & (C) (D) (B) & (C) 0 0 0 1

Given: abstract
interface DoMath class AllMath
{ implements
double getArea(int r); DoMath,
} interface MathPlus
interface MathPlus class AllMath AllMath { public class AllMath
Inheritance_In { extends implements double implements
terfaces_Abst double getVolume(int b, int h); DoMath MathPlus getArea(int MathPlus
ract } { double { double rad) { return { double
Classes_New /* Missing Statements ? */ getArea(int getVol(int x, rad * rad * getArea(int
QB Select the correct missing statements. MCQ r); } int y); } 3.14; } } rad); } 0 0 1 0
Consider the following code and choose the
correct option:
class A{
void display(byte a, byte b){
Inheritance_In System.out.println("sum of byte"+(a+b)); }
terfaces_Abst void display(int a, int b){
ract System.out.println("sum of int"+(a+b)); } Compiles but
Classes_New public static void main(String[] args) { Compilation error at
QB new A().display(3, 4); }} MCQ sum of byte 7 error sum of int7 runtime 0 0 1 0
Consider the following code and choose the
correct option:
interface Output{
void display();
void show();
}
Inheritance_In class Screen implements Output{
terfaces_Abst void display()
ract { System.out.println("display"); }public static Compiles but
Classes_New void main(String[] args) { Compilation error at run Runs but no
QB new Screen().display();}} MCQ display error time output 0 1 0 0

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_Abst }
ract }
Classes_New consider the code above & select the proper
QB output from the options. MCQ run time error generic noise bark compile error 1 0 0 0

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_Abst System.out.println("sal details"); }
ract public static void main(String[] args) {
Classes_New perEmp emp=new Programmer(); sal details compilation per details
QB emp.saldetails(); }} MCQ sal details per details error sal details 0 0 0 1
Consider the code below & select the correct
ouput from the options:
class A{
static int sq(int n){
return n*n; }}
Inheritance_In public class Test extends A{
terfaces_Abst static int sq(int n){
ract return super.sq(n); } Compiles but
Classes_New public static void main(String[] args) { Compilation error at run
QB System.out.println(new Test().sq(3)); }} MCQ 3 error time 9 0 1 0 0
No—a Yes—the
No—a variable must variable can
Inheritance_In Given: variable must always be an refer to any
terfaces_Abst public static void main( String[] args ) always be an object No—a object whose
ract { SomeInterface x; ... } object reference variable must class
Classes_New Can an interface name be used as the type of reference type or a always be a implements
QB a variable MCQ type primitive type primitive type the interface 0 0 0 1

Consider the following code and choose the


correct option:
interface A{
int i=3;}
interface B{
int i=4;}
Inheritance_In class Test implements A,B{
terfaces_Abst public static void main(String[] args) {
ract System.out.println(i); Compiles but
Classes_New } compilation error at
QB } MCQ 3 4 error runtime 0 0 1 0

Given the following classes and declarations,


which statements are true?
// Classes
class A {
private int i;
public void f() { /* ... */ }
public void g() { /* ... */ }
}
class B extends A{
public int j;
public void g() { /* ... */ }
Inheritance_In }
terfaces_Abst // Declarations:
ract A a = new A(); The B class The The The The
Classes_New B b = new B(); is a subclass statement statement a.j statement statement b.i
QB Select the three correct answers. MCA of A. b.f(); is legal = 5; is legal. a.g(); is legal = 3; is legal. 0.333333 0.333333 0 0.333333 0
Which declaration can be inserted at (1)
without causing a compilation error?
Inheritance_In interface MyConstants {
terfaces_Abst int r = 42; final double
ract int s = 69; circumferenc protected int
Classes_New // (1) INSERT CODE HERE int total = e=2* CODE = int AREA = r public static
QB } MCA total + r + s; Math.PI * r; 31337; * s; MAIN = 15; 0 0.5 0 0.5 0
What is the output for the following code:
abstract class One{
private abstract void test();
}
class Two extends One{
void test(){
System.out.println("hello");
}}
class Test{
Inheritance_In public static void main(String[] args){
terfaces_Abst Two obj = new Two();
ract obj.test();
Classes_New } run time compile time
QB } MCQ exception error hello hellohello 0 1 0 0
Consider the code below & select the correct
ouput from the options:

class Money {
private String country = "Canada";
Inheritance_In public String getC() { return country; } }
terfaces_Abst class Yen extends Money {
ract public String getC() { return super.country; } Compiles but
Classes_New public static void main(String[] args) { Compilation error at run
QB System.out.print(new Yen().getC() ); } } MCQ Canada error time null 0 1 0 0
we must use we must use
always always
Inheritance_In extends and implements
terfaces_Abst later we must and later we we can use in extends and
ract When we use both implements & extends use must use any order its implements
Classes_New keywords in a single java program then what implements extends not at all a can't be used
QB is the order of keywords to follow? MCQ keyword. keyword. problem together 1 0 0 0

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.)
Inheritance_In A. public int height(int x) { return 0; }
terfaces_Abst B. private int height(int x) { return 0; }
ract C. private int height(long x) { return 0; }
Classes_New D. protected long height(long x) { return 0; }
QB E. protected long height(int x) { return 0; } MCQ A,B,E A,C,D B,D,E C,D,E 0 1 0 0
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_Abst s += Easy + ++s;
ract System.out.println("s " + s);
Classes_New } Compilation
QB } What is the result? MCQ s 14 s 16 s 10 fails. 0 0 0 1

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()
Inheritance_In public void methodA() { } invokes the invokes the
terfaces_Abst public void methodB() { } //Line 9 Compilation version of Compilation version of
ract public void methodC() { } fails, due to methodB() fails, due to methodB()
Classes_New } an error in defined at line an error in defined at line
QB What would be the result? MCQ line 3 9 line 7 5 0 1 0 0
It must be It must be
Inheritance_In used in the used in the
terfaces_Abst It can only be last first
ract used in the Only one statement of statement of
Classes_New Which of the following statements is true parent's child class the the
QB regarding the super() method? MCQ constructor can use it constructor. constructor. 0 0 0 1

Consider the following code and choose the


correct option:
interface Output{
void display();
void show();
}
class Screen implements Output{
Inheritance_In void show() {System.out.println("show");}
terfaces_Abst void display()
ract { System.out.println("display"); }public static Compiles but
Classes_New void main(String[] args) { Compilation error at run Runs but no
QB new Screen().display();}} MCQ display error time output 0 1 0 0
Consider the following code and choose the
correct option:
class A{
void display(){ System.out.println("Hello
A"); }}
class B extends A{
void display(){
Inheritance_In System.out.println("Hello B"); }}
terfaces_Abst public class Test {
ract public static void main(String[] args) { Compiles but
Classes_New B b=(B) new A(); Compilation error at
QB b.display(); }} MCQ Hello A error Hello B runtime 0 0 0 1
Consider the following code:
// Class declarations: Definitely
class Super {} legal at Definitely
class Sub extends Super {} runtime, but legal at
Inheritance_In // Reference declarations: Legal at the cast runtime, and
terfaces_Abst Super x; compile time, operator the cast
ract Sub y; but might be (Sub) is not operator
Classes_New Which of the following statements is correct Illegal at illegal at strictly (Sub) is
QB for the code: y = (Sub) x? MCQ compile time runtime needed. needed. 0 1 0 0

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_Abst 23. ClassC p2 = new ClassC();
ract 24. ClassA p3 = new ClassB();
Classes_New 25. ClassA p4 = new ClassC(); p1 =
QB Which TWO are valid? (Choose two.) MCA p0 = p1; p2 = p4; (ClassB)p3; p1 = p2; 0.5 0 0.5 0

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(){
Inheritance_In System.out.print("150 mph"); }
terfaces_Abst public static void main(String[] args) {
ract Car mycar=new Lamborghini(); Compiles but
Classes_New Lamborghini lambo=(Lamborghini) mycar; Compilation error at
QB lambo.nitroBooster();}} MCQ 150 mph error 90 mph runtime 1 0 0 0
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"); }}
Inheritance_In public class Test {
terfaces_Abst public static void main(String[] args) {
ract A a=new B(); Compiles but
Classes_New B b= (B)a; Compilation error at
QB b.display(); }} MCQ Hello A error Hello B runtime 0 0 1 0
Because of
Because of single Because of Because of
Inheritance_In single inheritance, single single
terfaces_Abst inheritance, Mammal can inheritance, inheritance,
ract Mammal can have no other Animal can Mammal can
Classes_New A class Animal has a subclass Mammal. have no parent than have only one have no
QB Which of the following is true: MCQ subclasses Animal subclass siblings. 0 1 0 0

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_Abst }
ract }
Classes_New consider the code above & select the proper
QB output from the options. MCQ run time error generic noise bark compile error 0 0 1 0
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);
}
}

public class Pri1 extends Base1 {


static int i = 200;

Inheritance_In public static void main(String argv[]) {


terfaces_Abst Pri1 p = new Pri1();
ract System.out.println(i);
Classes_New } Error at 100 followed
QB } MCQ compile time 200 by 200 100 0 0 1 0

What is the output :


interface A{
void method1();
void method2();
}
class Test implements A{
public void method1(){
System.out.println("hello");}}
Inheritance_In class RunTest{
terfaces_Abst public static void main(String[] args){
ract Test obj = new Test();
Classes_New obj.method1();
QB }} MCQ hello compile error runtime error none 0 1 0 0

Given the following classes and declarations,


which statements are true?
// Classes
class Foo {
private int i;
public void f() { /* ... */ }
public void g() { /* ... */ }
}
class Bar extends Foo {
public int j;
Inheritance_In public void g() { /* ... */ }
terfaces_Abst }
ract // Declarations: The Bar class The The The
Classes_New Foo a = new Foo(); is a subclass statement a.j statement statement
QB Bar b = new Bar(); MCA of Foo. = 5; is legal. b.f(); is legal. a.g(); is legal. 0.333333 0 0.333333 0.333333
Inheritance_In
terfaces_Abst Given a derived class method which overrides by creating cannot call
ract one of it’s base class methods. With derived an instance because it is
Classes_New class object you can invoke the overridden super of the base overridden in
QB base method using: MCQ keyword this keyword class derived class 1 0 0 0
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");
Inheritance_In } void nitroBooster(){
terfaces_Abst System.out.print("150 mph"); }
ract public static void main(String[] args) { Compiles but
Classes_New Car mycar=new Lamborghini(); Compilation error at run
QB mycar.nitroBooster(); }} MCQ error time 90 mph 150 mph 1 0 0 0

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) {
Inheritance_In Pizza pizza = new PepperoniPizza();
terfaces_Abst pizza.addTopping("Mushrooms"); A
ract } The code NullPointerEx
Classes_New } Compilation Cannot add runs with no ception is
QB What is the result? MCQ fails. Toppings output. thrown 1 0 0 0
Consider the following code and choose the
correct option:
interface console{
int line=10;
void print();}
Inheritance_In class a implements console{
terfaces_Abst void print(){
ract System.out.print("A");} Compiles but
Classes_New public static void main(String ar[]){ Compilation error at run Runs but no
QB new a().print();}} MCQ A error time output 0 1 0 0
Inheritance_In
terfaces_Abst
ract private final public static
Classes_New Which of these field declarations are legal in public int final static int static int int answer =
QB an interface? (Choose all applicable) MCA answer = 42; answer = 42; answer = 42; int answer; 42; 0.25 0.25 0.25 0 0.25
Given :
No—there No—but a
Day d; must always object of Yes—an
Inheritance_In BirthDay bd = new BirthDay("Raj", 25); be an exact parent type object can be Yes—any
terfaces_Abst d = bd; // Line X match can be assigned to a object can be
ract between the assigned to a reference assigned to
Classes_New Where Birthday is a subclass of Day. State variable and variable of variable of the any reference
QB whether the code given at Line X is correct: MCQ the object child type. parent type. variable. 0 0 1 0
If both a
subclass and If neither Calling
its super() nor super() as the
superclass this() is first
do not have declared as statement in
A super() or any declared the first If super() is the body of a
this() call constructors, statement in the first constructor of
must always the implicit the body of a statement in a subclass
be provided default constructor, the body of a will always
Inheritance_In explicitly as constructor of this() will constructor, work, since
terfaces_Abst the first the subclass implicitly be this() can be all
ract statement in will call inserted as declared as superclasses
Classes_New the body of a super() when the first the second have a default
QB Select the correct statement: MCQ constructor. run statement. statement constructor. 0 1 0 0 0
Inheritance_In
terfaces_Abst public final final data
ract data type static final type
Classes_New Choose the correct declaration of variable in varaibale=inti static data data type variablename
QB an interface: MCQ alization; type variable; varaiblename; =intialization; 1 0 0 0

Consider the following code and choose the


correct option:
abstract class Fun{
void time(){
System.out.println("Fun Time"); }}
class Run extends Fun{
Inheritance_In void time(){
terfaces_Abst System.out.println("Fun Run"); }
ract public static void main(String[] args) { Compiles but
Classes_New Fun f1=new Run(); Compilation error at
QB f1.time(); }} MCQ Fun Time error Fun Run runtime 0 0 1 0

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_Abst obj.drive();
ract }}
Classes_New consider the code above & select the proper
QB output from the options. MCQ Auto Bicycle Auto compile error runtime error 0 0 1 0
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_Abst class Programmer extends perEmp{
ract public static void main(String[] args) {
Classes_New perEmp emp=new Programmer(); sal details compilation per details
QB emp.saldetails(); }} MCQ sal details per details error sal details 0 0 1 0
Inheritance_In
terfaces_Abst
ract
Classes_New All data members in an interface are by abstract and public and public ,static default and
QB default MCQ final abstract and final abstract 0 0 1 0
Consider the following code and choose the
correct option:
interface console{
int line;
void print();}
Inheritance_In class a implements console{
terfaces_Abst public void print(){
ract System.out.print("A");} Compiles but
Classes_New public static void main(String ar[]){ Compilation error at run Runs but no
QB new a().print();}} MCQ A error time output 0 1 0 0
An abstract
class is one
An abstract which
class is one contains An abstract
Inheritance_In which some defined class is one
terfaces_Abst contains methods and which
ract general some contains only Abstract
Classes_New Which of the following is correct for an purpose undefined static class can be
QB abstract class. (Choose TWO) MCA methods methods methods declared final 0.5 0.5 0 0

abstract
class class Vehicle
Inheritance_In abstract abstract { abstract abstract
terfaces_Abst class Vehicle Vehicle Vehicle void display(); class Vehicle
ract { abstract { abstract { abstract { System.out. { abstract
Classes_New Which of the following defines a legal abstract void void void println("Car"); void
QB class? MCQ display(); } display(); } display(); } }} display(); } 0 0 0 0 1
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 Alps extends Mountain{


public Alps(int h){ super(h); }
Inheritance_In public Alps(){ this(100); }
terfaces_Abst public static void main(String[] args) {
ract System.out.println(new Alps().getH()); Compiles but
Classes_New } Compilation error at run Compiles but
QB } MCQ 100 error time no output 1 0 0 0

Consider the given code and select the


correct output:

class SomeException {
}

class A {
public void doSomething() { }
} Compilation Compilation
Inheritance_In of class A will of class B will
terfaces_Abst class B extends A { Compilation Compilation fail. fail.
ract public void doSomething() throws of both of both Compilation Compilation
Classes_New SomeException { } classes A & classes will of class B will of class A will
QB } MCQ B will fail succeed succeed succeed 0 0 0 1

No—if a
class
implements
several Yes— either
interfaces, of the two
each variables can
Inheritance_In constant No—a class be accessed Yes—since
terfaces_Abst must be may not through : the definitions
ract Is it possible if a class definition implements defined in implement interfaceNam are the same
Classes_New two interfaces, each of which has the same only one more than e.variableNa it will not
QB definition for the constant? MCQ interface one interface me matter 0 0 1 0

The
An overriding parameter list
method can of an
declare that it overriding
throws method can
checked be a subset The overriding
Inheritance_In Private A subclass exceptions of the method must
terfaces_Abst methods can override that are not parameter list have different
ract cannot be any method thrown by the of the method return type as
Classes_New overridden in in a method it is that it is the overridden
QB Select the correct statement: MCQ subclasses superclass overriding overriding method 1 0 0 0 0
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"); }}
Inheritance_In public class Test {
terfaces_Abst public static void main(String[] args) {
ract A a=new B(); Compiles but
Classes_New B b= a; Compilation error at
QB b.display(); }} MCQ Hello A error Hello B runtime 0 1 0 0

Helps the
compiler to
find the
source file
that
corresponds
to a class,
when it does Helps
Which of the following option gives one not find a Helps JVM to Javadoc to
Introduction_t possible use of the statement 'the name of To maintain class file find and build the Java
o_Java_and_ the public class should match with its file the uniform while execute the Documentatio
SDE_NewQB name'? MCQ standard compiling classes n easily 0 1 0 0
Holds the Holds the
location of Holds the location of
Core Java location of User Defined
Introduction_t Class Library Java classes, Holds the
o_Java_and_ Which of the following statement gives the (Bootstrap Extension packages location of
SDE_NewQB use of CLASSPATH? MCQ classes) Library and JARs Java Software 0 0 1 0

Class and
Interfaces in
the sub
packages will
Sub be
Packages Packages packages automatically
can contain can contain should be available to
both Classes non-java declared as the outer
Packages and elements private in packages
Introduction_t can contain Interfaces such as order to deny without using
o_Java_and_ Which of the following are true about only Java (Compiled images, xml importing import
SDE_NewQB packages? (Choose 2) MCA Source files Classes) files etc. them statement. 0 0.5 0.5 0 0
Introduction_t Which of the following options give the valid
o_Java_and_ argument types for main() method? (Choose
SDE_NewQB 2) MCA String [][]args String args String[] args[] String[] args String args[] 0 0 0 0.5 0.5
Introduction_t dollorpack. p@ckage.sub .package.sub
o_Java_and_ Which of the following options give the valid $pack.$ _score.pack. p@ckage.inn package.inne
SDE_NewQB package names? (Choose 3) MCA $pack $$.$$.$$ __pack erp@ckage rpackage 0.333333 0.333333 0.333333 0 0
Object class
provides the
Object class method for
has the core Set Object class
Object class methods for implementati implements
Introduction_t Object class cannot be thread on in Serializable
o_Java_and_ Which of the following statements are true is an abstract instantiated synchronizati Collection interface
SDE_NewQB regarding java.lang.Object class? (Choose 2) MCA class directly on framework internally 0 0 0.5 0.5 0
Java
Introduction_t Java Runtime Database
o_Java_and_ The term 'Java Platform' refers to Java Compiler Environment Connectivity Java
SDE_NewQB ________________. MCQ (Javac) (JRE) (JDBC) Debugger 0 1 0 0
registerDriver(
) method and
JDBC_NewQ Which of the following methods are needed for registerDriver( Class.forNam Class.forNam getConnectio
B loading a database driver in JDBC? MCQ ) method e() e() n 0 0 1 0
Using the
static method
registerDriver(
) method
Using which is Either
forName() available in forName() or
JDBC_NewQ which is a DriverManage registerDriver( None of the
B how to register driver class in the memory? MCQ static method r Class. ) given options 0 0 1 0

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 java.sql.Driver java.sql.Conn
B ResultSet? MCQ tSet java.sql.Driver Manager ection 1 0 0 0

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
JDBC_NewQ System.out.println(rs.getString(1)+ " employee Compilation error at run Compiles but
B "+rs.getString(2)); MCQ record error time no output 0 0 1 0
Which of the following methods finds the Connection.g ResultSetMet DatabaseMet Database.get
JDBC_NewQ maximum number of connections that a etMaxConnec aData.getMa aData.getMa MaxConnecti
B specific driver can obtain? MCQ tions xConnections xConnections ons 0 0 1 0
JDBC_NewQ By default all JDBC transactions are
B autocommit. State TRUE/FALSE. MCQ true false 1 0
PreparedStat
JDBC_NewQ DriverManage Driver ResultSet Statement ement
B getConnection() is method available in? MCQ r Class Interface Interface Interface Interface 1 0 0 0 0
A) By default, all JDBC transactions are auto
commit
B) PreparedStatement suitable for dynamic
sql and requires one time compilation
JDBC_NewQ C) with JDBC it is possible to fetch Only A and B Only B and C Both A and C
B information about the database MCQ is TRUE is True is TRUE All are TRUE 0 0 0 1

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
JDBC_NewQ What is the use of wasNull() in ResultSet in ResultSet NULL else contains Null none of the
B interface? MCQ interface returns false value listed options 0 1 0 0

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());
// Some code java.sql.Driver
JDBC_NewQ } Inorder to compile & execute this code, what java.sql.Driver java.sql.Data
B should we import? MCQ java.sql.Driver java.sql.Driver Manager Source 0 0 1 0
Which of the following method can be used to
JDBC_NewQ execute to execute all type of queries i.e. executeAllSQ executeQuer executeUpdat
B either Selection or Updation SQL Queries? MCQ executeAll() L() execute() y() e() 0 0 1 0 0

JDBC_NewQ Which method will return boolean when we try executeUpdat executeQuer
B to execute SQL Query from a JDBC program? MCQ e() executeSQL() execute() y() 0 0 1 0
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
JDBC_NewQ while(rs.next()){ will show only Compilation error at run
B System.out.println(rs.getString(3)); } MCQ name error will show city time 0 0 0 1

JDBC_NewQ It is possible to insert/update record in a table


B by using ResultSet. State TRUE/FALSE MCQ true false 1 0
Read only, Updatable,
JDBC_NewQ What is the default type of ResultSet in JDBC Read Only, Updatable, Scroll Scroll
B applications? MCQ Forward Only Forward only Sensitive sensitive 1 0 0 0
An application can connect to different
JDBC_NewQ Databases at the same time. State TRUE/
B FALSE. MCQ true false 1 0
A) It is not possible to execute select query
with execute() method
JDBC_NewQ B) CallableStatement can executes store Both A and B Only A is Only B is Both A and B
B procedures only but not functions MCQ is FALSE TRUE TRUE is TRUE 1 0 0 0
A) When one use callablestatement, in that
case only parameters are send over network
not sql query.
JDBC_NewQ B) In preparestatement sql query will compile Both A and B Both A and B Only A is Only B is
B for first time only MCQ is FALSE is TRUE TRUE TRUE 0 1 0 0

Consider the code below & select the correct


ouput from the options:

String sql ="select * from ?";


String table=" txyz ";
PreparedStatement
pst=cn.prepareStatement(sql);
pst.setString(1,table );
ResultSet rs=pst.executeQuery(); will show all Compiles but Compiles but
JDBC_NewQ while(rs.next()){ row of first Compilation error at run run without
B System.out.println(rs.getString(1)); } MCQ column error time output 0 0 1 0
Sylvy wants to develop Student management
system, which requires frequent insert
operation about student details. In order to
JDBC_NewQ insert student record which statement CallableState PreparedStat
B interface will give good performance MCQ Statement ment ement RowSet 0 0 1 0

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) { Line 13
e.printStackTrace } creates a
}}} Line 13 directory
If the current direcory does not consists of Line 16 is An exception creates a File named “c” in
JDBC_NewQ directory "c", Which statements are true ? never is thrown at object named the file
B (Choose TWO) MCA executed runtime “c” system. 0 0.5 0.5 0
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)
PreparedStat PreparedStat
1) Driver 2) ement 8) ement 7)
Connection 3) Callablestate Callablestate
ResultSet 4) ment 9) ment 8)
JDBC_NewQ Which of the following options contains only DriverManage DataBaseMet DataBaseMet All of the
B JDBC interfaces? MCQ r 5) Class aData aData given options 0 0 1 0

Consider the code below & select the correct


ouput from the options:

public class Test {


public static void main(String [] args) {
int x = 5;
boolean b1 = true;
boolean b2 = false;
if ((x == 4) && !b2 )
Keywords_var System.out.print("1 ");
iables_operat System.out.print("2 ");
ors_datatype if ((b2 = true) && b1 )
s_NewQB System.out.print("3 "); } MCQ 23 13 2 3 1 0 0 0
Keywords_var
iables_operat
ors_datatype Which three are legal array declarations? int [] char [] int [6] Dog myDogs Dog myDogs
s_NewQB (Choose THREE) MCA myScores []; myChars; myScores; []; [7]; 0.333333 0.333333 0 0.333333 0
Consider the given code and select the
correct output:
class Test{
public static void main(String[] args){
Keywords_var int num1 = 012;
iables_operat int num2 = 0x110; Compiles but
ors_datatype int sum =num1+=num2; error at run Compilation
s_NewQB System.out.println("Ans = "+sum); }} MCQ 26 282 time error 0 1 0 0

Say that class Rodent has a child class Rat


and another child class Mouse. Class Mouse
has a child class PocketMouse. Examine the
following

Rodent rod;
Rat rat = new Rat();
Mouse mos = new Mouse();
Keywords_var PocketMouse pkt = new PocketMouse();
iables_operat
ors_datatype Which one of the following will cause a
s_NewQB compiler error? MCQ rod = mos pkt = rat pkt = null rod = rat 0 1 0 0
Consider the code below & select the correct
ouput from the options:
class Test{
public static void main(String[] args) {
parse("Four"); } A
static void parse(String s){ A NumberForm
try { ParseExcepti atException
Keywords_var double d=Double.parseDouble(s); on is thrown is thrown by
iables_operat }catch(NumberFormatException nfe){ by the parse the parse
ors_datatype d=0.0; }finally{ Compilation method at method at
s_NewQB System.out.println(d); } }} MCQ error runtime runtime 0 1 0 0

Consider the code below & select the correct


ouput from the options:
class A{
public int a=7;
public void add(){
this.a+=2; System.out.print("a"); }}

public class Test extends A{


public int a=2;
public void add(){
this.a+=2; System.out.print("t"); }
Keywords_var public static void main(String[] args) {
iables_operat A a =new Test();
ors_datatype a.add(); Compilation
s_NewQB System.out.print(a.a); }} MCQ t7 t9 a9 error 1 0 0 0

What will be the output of the program?

public class CommandArgsTwo


{
public static void main(String [] argh)
{
int x;
x = argh.length;
for (int y = 1; y <= x; y++)
{
System.out.print(" " + argh[y]);
}
}
}
Keywords_var
iables_operat and the command-line invocation is An exception
ors_datatype is thrown at
s_NewQB > java CommandArgsTwo 1 2 3 MCQ 012 23 000 runtime 0 0 0 1
What will be the result of the following
program?
public class Init {
String title;
boolean published;
static int total;
static double maxPrice;
public static void main(String[] args) {
Init initMe = new Init();
double price;
if (true)
price = 100.00;
System.out.println("|" + initMe.title + "|" + The program The program The program The program
initMe.published + "|" + will compile, will compile, will compile, will compile,
Keywords_var Init.total + "|" + Init.maxPrice + "|" + price+ and print |null| and print |null| and print | | and print |null|
iables_operat "|"); false|0|0.0| true|0|0.0| false|0|0.0| false|0|0.0|
ors_datatype } 0.0|, when 100.0|, when 0.0|, when 100.0|, when Compilation
s_NewQB } MCQ run run run run error 0 0 0 1 0

Here is the general syntax for method


definition: The
The returnValue
accessModifier returnType returnValue must be the
methodName( parameterList ) can be any same type as
{ type, but will the
Java statements be returnType, or
The automatically be of a type
return returnValue; returnValue converted to If the that can be
} must be returnType returnType is converted to
Keywords_var exactly the when the void then the returnType
iables_operat same type as method returnValue without loss
ors_datatype What is true for the returnType and the the returns to the can be any of
s_NewQB returnValue? MCQ returnType caller. type information. 0 0 0 1
Consider the following code and choose the
correct option:
class Test{
class A{ static int x=3; }
Keywords_var static void display(){
iables_operat System.out.println(A.x); } Compiles but
ors_datatype public static void main(String[] args) { Compilation error at run
s_NewQB display(); }} MCQ 3 error time 0 1 0 0
Which of the following lines of code will
compile without warning or error?
1) float f=1.3;
Keywords_var 2) char c="a";
iables_operat 3) byte b=257;
ors_datatype 4) boolean b=null; Line 1, Line
s_NewQB 5) int i=10; MCQ Line 3 3, Line 5 Line 1, Line 5 Line 4 Line 5 0 0 0 0 1
Consider the following code and choose the
correct option:
class Test{
interface Y{
void display(); }
public static void main(String[] args) {
Keywords_var new Y(){
iables_operat public void display(){ Compiles but Compiles but
ors_datatype System.out.println("Hello World"); } Compilation error at run run without
s_NewQB }.display(); }} MCQ Hello World error time output 1 0 0 0
Consider the following code and choose the
correct option:
class Test{
static class A{
interface X{
int z=4; } }
Keywords_var static void display(){
iables_operat System.out.println(A.X.z); } Compiles but
ors_datatype public static void main(String[] args) { Compilation error at run
s_NewQB display(); }} MCQ 4 error time 1 0 0 0

What is the output of the following program?


public class MyClass
{
public static void main( String[] args )
{
private static final int value =9;
float total;
Keywords_var total = value + value / 2;
iables_operat System.out.println( total );
ors_datatype } Compilation
s_NewQB } MCQ 13 13.5 13 Error Runtime Error 0 0 0 1 0
Keywords_var Which of the given options is similar to the
iables_operat following code: value = value sum = sum +
ors_datatype + sum; sum 1; value = value = value value = value
s_NewQB value += sum++ ; MCQ = sum + 1; value + sum; + sum; + ++sum; 1 0 0 0
What will happen if you attempt to compile
and run the following code?
Integer ten=new Integer(10);
Keywords_var Long nine=new Long (9);
iables_operat System.out.println(ten + nine);
ors_datatype int i=1; 19 followed 19 follwed by Compile time 10 followed
s_NewQB System.out.println(i + ten); MCQ by 11 20 error by 1 1 0 0 0
Identify the statements that are correct:
Keywords_var (A) int a = 13, a>>2 = 3
iables_operat (B) int b = -8, b>>1 = -4
ors_datatype (C) int a = 13, a>>>2 = 3 (A), (B), (C) &
s_NewQB (D) int b = -8, b>>>1 = -4 MCQ (A), (B) & (C) (D) (C) & (D) (A) & (B) 1 0 0 0
Consider the following code:
int x, y, z;
y = 1;
Keywords_var z = 5;
iables_operat x = 0 - (++y) + z++;
ors_datatype After execution of this, what will be the values x = -7, y = 1, x = 3, y = 2, x = 4, y = 1, x = 4, y = 2,
s_NewQB of x, y and z? MCQ z=5 z=6 z=5 z=6 0 1 0 0
Here is the general syntax for method
definition:

accessModifier returnType
methodName( parameterList ) It can be
{ omitted, but if
Java statements not omitted
there are The access It can be
return returnValue; several modifier must omitted, but if
Keywords_var } It must choices, agree with not omitted it
iables_operat always be including the type of must be
ors_datatype private or private and the return private or
s_NewQB What is true for the accessModifier? MCQ public public value public 0 1 0 0

What will be the output of the program?

public class CommandArgs


{
public static void main(String [] args)
{
String s1 = args[1];
String s2 = args[2];
String s3 = args[3];
String s4 = args[4];
System.out.print(" args[2] = " + s2);
}
}
Keywords_var
iables_operat and the command-line invocation is An exception
ors_datatype is thrown at
s_NewQB > java CommandArgs 1 2 3 4 MCQ args[2] = 2 args[2] = 3 args[2] = null runtime 0 0 0 1
Consider the following code snippet:
Keywords_var int i = 10;
iables_operat int n = ++i%5;
ors_datatype What are the values of i and n after the code
s_NewQB is executed? MCQ 10, 1 11, 1 10, 0 11 , 0 0 1 0 0
Keywords_var
iables_operat int [] myList
ors_datatype Which will legally declare, construct, and = {"1", "2", int [] myList int myList [] int myList []
s_NewQB initialize an array? MCQ "3"}; = (5, 8, 2); [] = {4,9,7,0}; = {4, 3, 7}; 0 0 0 1

Consider the code below & select the correct


ouput from the options:
public class Test {
public static void main(String[] args) {
int x=5;
Test t=new Test();
t.disp(x);
System.out.println("main X="+x);
Keywords_var }
iables_operat void disp(int x) {
ors_datatype System.out.println("disp X = "+x++); disp X = 6 disp X = 5 disp X = 5 Compilation
s_NewQB }} MCQ main X=6 main X=5 main X=6 error 0 1 0 0
How many objects and reference variables are
Keywords_var created by the following lines of code? Two objects Three objects Four objects Two objects
iables_operat Employee emp1, emp2; and three and two and two and two
ors_datatype emp1 = new Employee() ; reference reference reference reference
s_NewQB Employee emp3 = new Employee() ; MCQ variables. variables variables variables. 1 0 0 0
A) The purpose of the method overriding is to
perform different operation, though input
Keywords_var remains the same.
iables_operat B) one of the important Object Oriented
ors_datatype principle is the code reusability that can be Only A is Only B is Both A and B Both A and B
s_NewQB achieved using abstraction MCQ TRUE True is True is FALSE 1 0 0 0
class Test{
public static void main(String[] args){
byte b=(byte) (45 << 1);
Keywords_var b+=4;
iables_operat System.out.println(b); }} Compiles but
ors_datatype What should be the output for the code error at run Compilation
s_NewQB written above? MCQ 48 94 time error 0 1 0 0
Keywords_var What is the value of y when the code below is
iables_operat executed?
ors_datatype int a = 4;
s_NewQB int b = (int)Math.ceil(a % 3 + a / 3.0); MCQ 1 2 3 4 0 0 1 0
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); } Compiles but
ors_datatype public static void main(String[] args) { Compilation error at run
s_NewQB display(); }} MCQ error time 4 0 1 0 0
Consider the code below & select the correct
ouput from the options:
public class Test {
public static void main(String[] args) {
Keywords_var String[] elements = { "for", "tea", "too" };
iables_operat String first = (elements.length > 0) ? The variable The variable Compiles but
ors_datatype elements[0] : null; Compilation first is set to first is set to error at
s_NewQB System.out.println(first); }} MCQ error null. elements[0]. runtime 0 0 1 0

Given the following piece of code:


public class Test {
public static void main(String args[]) {
int i = 0, j = 5 ;
for( ; (i < 3) && (j++ < 10) ; i++ ) {
System.out.print(" " + i + " " + j );
}
Keywords_var System.out.print(" " + i + " " + j );
iables_operat }
ors_datatype } 0617283 0617283 0515253 compilation
s_NewQB what will be the output? MCQ 8 9 5 fails 1 0 0 0
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_datatype } 83886080 2 and 2 and 83886080
s_NewQB } MCQ and -2 83886080 -83886080 and 2 0 0 0 1

Consider the code below & select the correct


ouput from the options:

public class Test {


int squares = 81;
public static void main(String[] args) {
new Test().go(); }
Keywords_var void go() {
iables_operat incr(++squares);
ors_datatype System.out.println(squares); } Compilation
s_NewQB void incr(int squares) { squares += 10; } } MCQ 92 91 error 82 0 0 0 1
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_datatype Consider the code above & select the correct compile time compile time runtime none of the
s_NewQB output. MCQ error at line 2 error at line 4 prints 34,56 exception listed options 0 1 0 0 0

What will be the output of the program ?

public class Test


{
public static void main(String [] args)
{
signed int x = 10;
Keywords_var for (int y=0; y<5; y++, x--)
iables_operat System.out.print(x + ", "); An exception
ors_datatype } Compilation is thrown at
s_NewQB } MCQ 10, 9, 8, 7, 6, 9, 8, 7, 6, 5, fails runtime 0 0 1 0
1. public class LineUp {
2. public static void main(String[] args) {
3. double d = 12.345;
4. // insert code here
5. }
6. }
Which code fragment, inserted at line 4,
produces the output | 12.345|?

Keywords_var A. System.out.printf("|%7f| \n", d);


iables_operat B. System.out.printf("|%3.7f| \n", d);
ors_datatype C. System.out.printf("|%7.3d| \n", d);
s_NewQB D. System.out.printf("|%7.3f| \n", d); MCQ A B C D 0 0 0 1
Consider the following code and choose the
correct option:
class Test{
interface Y{
void display(); }
public static void main(String[] args) {
Keywords_var Y y=new Y(){
iables_operat public void display(){ Compiles but Compiles but
ors_datatype System.out.println("Hello World"); } }; Compilation error at run run without
s_NewQB y.display(); }} MCQ Hello World error time output 1 0 0 0
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_datatype consider the code above & select the proper runs with no does not
s_NewQB output from the options. MCQ output var = 1 compile run time error 0 0 1 0

State the class relationship that is being


implemented by the following code:
class Employee
{
private int empid;
private String ename;
public double getBonus()
{
Accounts acc = new Accounts();
return acc.calculateBonus();
}
}

class Accounts
Keywords_var {
iables_operat public double calculateBonus(){//method's
ors_datatype code} Simple
s_NewQB } MCQ Aggregation Association Dependency Composition 0 0 1 0
Given classes A, B, and C, where B extends
Keywords_var A, and C extends B, and where all classes
iables_operat implement the instance method void doIt().
ors_datatype How can the doIt() method in A be It is not his.super.doIt ((A)
s_NewQB called from an instance method in C? MCQ possible super.doIt() () this).doIt(); A.this.doIt() 1 0 0 0 0
Keywords_var
iables_operat int [] a =
ors_datatype Which of the following will declare an array Array a = {23,22,21,20, int a [] = new
s_NewQB and initialize it with five numbers? MCQ new Array(5); 19}; int[5]; int [5] array; 0 1 0 0
Keywords_var
iables_operat
ors_datatype Which of the following are correct variable
s_NewQB names? (Choose TWO) MCA int #ss; int 1ah; int _; int $abc; 0 0 0.5 0.5
What is the output of the following:

int a = 0;
Keywords_var int b = 10;
iables_operat
ors_datatype a = --b ;
s_NewQB System.out.println("a: " + a + " b: " + b ); MCQ a: 9 b:11 a: 10 b: 9 a: 9 b:9 a: 0 b:9 0 0 1 0
As per the following code fragment, what is
the value of a?
Keywords_var String s;
iables_operat int a;
ors_datatype s = "Foolish boy.";
s_NewQB a = s.indexOf("fool"); MCQ -1 4 random value 1 0 0 0
Consider the following code snippet:
Keywords_var int i = 10;
iables_operat int n = i++%5;
ors_datatype What are the values of i and n after the code
s_NewQB is executed? MCQ 10, 1 11, 1 10, 0 11 , 0 0 0 0 1
Consider the following code and choose the
correct output:

int value = 0;
Keywords_var int count = 1;
iables_operat value = count++ ;
ors_datatype System.out.println("value: "+ value + " count: value: 0 value: 0 value: 1 value: 1
s_NewQB " + count); MCQ count: 0 count: 1 count: 1 count: 2 0 0 0 1
Consider the following code and select the
correct output:
class Test{
interface Y{
void display(); }
public static void main(String[] args) {
Keywords_var new Y(){
iables_operat public void display(){ Compiles but Compiles but
ors_datatype System.out.println("Hello World"); } }; Compilation error at run run without
s_NewQB }} MCQ Hello World error time output 0 0 0 1
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++)
Keywords_var System.out.println(arr[j]); A sequence
iables_operat A sequence of Garbage
ors_datatype } of five 10's Values are compile time Compiles but
s_NewQB } MCQ are printed printed Error no output 0 0 1 0
Threads_New Which of the following methods registers a
QB thread in a thread scheduler? MCQ run(); construct(); start(); register(); 0 0 1 0

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
Threads_New } could be 5-1 could be 6-1 could be 6-1 could be 6-1
QB Which statement is true? MCQ 6-1 6-2 5-2 6-2 5-1 5-2 5-2 6-2 5-1 6-2 5-1 7-1 0 1 0 0

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
Threads_New th1.run(); Exception at will print Hi Compilation will print Hi
QB }} MCQ run time Thrice error once 0 1 0 0
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
Threads_New th1.start(); will start two will print Hi exception at
QB }} MCQ thread Once will not print runtime 0 0 0 1
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
Threads_New Cthread th2=new Cthread(); display Hi compilation any child will display Hi
QB }} MCQ twice error thread once 1 0 0 0
Threads_New Which of the following methods are defined in
QB class Thread? (Choose TWO) MCA start() wait() notify() run() terminate() 0.5 0 0 0.5 0
The following block of code creates a Thread
using a Runnable target:

Runnable target = new MyRunnable(); public class public class


Thread myThread = new Thread(target); MyRunnable MyRunnable public class public class
implements extends MyRunnable MyRunnable
Which of the following classes can be used to Runnable{pub Runnable{pub implements extends
Threads_New create the target, so that the preceding code lic void run() lic void run() Runnable{void Object{public
QB compiles correctly? MCQ {}} {}} run(){}} void run(){}} 1 0 0 0
Extend Implement Implement Implement
Extend java.lang.Run java.lang.Thre java.lang.Run java.lang.Thre
java.lang.Thre nable and ad and nable and ad and
ad and override the implement implement implement
Threads_New Which of the following statements can be override the start() the run() the run() the start()
QB used to create a new Thread? (Choose TWO) MCA run() method. method. method. method method. 0.5 0 0 0.5 0

What will be the output of the program?

class MyThread extends Thread


{
MyThread() {}
MyThread(Runnable r) {super(r); }
public void run()
{
System.out.print("Inside Thread ");
}
}
class MyRunnable implements Runnable
{
public void run()
{
System.out.print(" Inside Runnable");
}
}
class Test
{
public static void main(String[] args)
{
new MyThread().start();
new MyThread(new
MyRunnable()).start(); Prints "Inside Prints "Inside Throws
Threads_New } Thread Inside Does not Thread Inside exception at
QB } MCQ Thread" compile Runnable" runtime 1 0 0 0
A) Multiple processes share same memory
location
B) Switching from one thread to another is
easier than switching from one process to
another
C) Thread makes it possible to maximize
Threads_New resource utilization All are Only B and C Only A and B Only C and D
QB D) Process is a light weight program MCQ FALSE is TRUE is TRUE is TRUE 0 1 0 0
A) Exception is the superclass of all errors
and exceptions in the java language
Threads_New B) RuntimeException and its subclasses are Only A is Only B is Both A and B Both A and B
QB unchecked exception. MCQ TRUE TRUE are TRUE are FALSE 0 1 0 0

What will be the output of the program?

class MyThread extends Thread


{
public static void main(String [] args)
{
MyThread t = new MyThread();
t.start();
System.out.print("one. ");
t.start();
System.out.print("two. ");
}
public void run()
{
System.out.print("Thread "); An exception It prints The output
Threads_New } Compilation occurs at "Thread one. cannot be
QB } MCQ fails runtime. Thread two." determined. 0 1 0 0
Consider the following code and choose the
correct option:
class A implements Runnable{ int k;
public void run(){
k++; } Compiles but
public static void main(String args[]){ throws run
Threads_New A a1=new A(); It will start a compilation time a1 is not a
QB a1.run();} MCQ new thread error Exception Thread 0 0 0 1

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(); The code
t.start(); The code executes
} An exception executes normally, but
Threads_New } Compilation is thrown at normally and nothing is
QB What is the result? MCQ fails. runtime. prints "run". printed. 0 1 0 0
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); The code
t.start(); executes
}} An exception normally and
Threads_New what should be the correct output for the code Compilation is thrown at prints "Good prints Good
QB written above? MCQ fails. runtime. Day.." Day.. Twice 0 0 1 0
public class MyRunnable implements
Runnable
{
public void run()
{
// some code here
} new new
} Runnable(My new new Thread(new
Threads_New which of these will create and start this Runnable).sta Thread(MyRu MyRunnable() MyRunnable()
QB thread? MCQ rt(); nnable).run(); .start(); ).start(); 0 0 0 1
Consider the following code and choose the
correct option:
class Nthread extends Thread{
public void run(){
System.out.print("Hi");} Will create
public static void main(String args[]){ two child
Nthread th1=new Nthread(); threads and will not create
Threads_New Nthread th2=new Nthread(); display Hi compilation any child will display Hi
QB } MCQ twice error thread once 0 0 1 0
Assume the following method is properly
synchronized and called from a thread A on
an object B:

wait(2000); After the lock


After thread A on B is
After calling this method, when will the thread is notified, or released, or Two seconds Two seconds
Threads_New A become a candidate to get another turn at after two after two after thread A after lock B is
QB the CPU? MCQ seconds. seconds. is notified. released. 1 0 0 0
Threads_New wait(), notify() and notifyAll() methods belong Interrupt none of the
QB to ________ MCQ Object class Thread class class listed options 1 0 0 0
Consider the following code and choose the
correct option:
class Test {
public static void main(String[] args) {
new Test().display("hi", 1);
strings_string new Test().display("hi", "world", 2); }
_buffer_NewQ public void display(String... s, int x) { Compilation
B System.out.print(s[s.length-x] + " "); } } MCQ hi hi hi world world error 0 0 0 1
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) {
strings_string String name="Anthony Gomes";
_buffer_NewQ int a=111; Compilation
B System.out.println(name.indexOf(a)); }} MCQ 4 2 6 error 1 0 0 0
Given:
String test = "This is a test";
strings_string String[] tokens = test.split("\s");
_buffer_NewQ System.out.println(tokens.length); Compilation
B What is the result? MCQ 1 4 fails. 0 0 0 1
Consider the following code and choose the
correct option:
public class Test {
strings_string public static void main(String[] args) { Compiles but
_buffer_NewQ String data="78"; Compilation exception at
B System.out.println(data.append("abc")); }} MCQ 78abc abc78 error run time 0 0 1 0
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) {
strings_string String name="ALDPR7882E";
_buffer_NewQ System.out.println(name.endsWith("E") &
B name.matches("[A-Z]{5}[0-9]{4}[A-Z]"));}} MCQ false true 1 0 1 0 0
Examine this code:

String stringA = "Hello ";


String stringB = " World"; result = result =
String stringC = " Java"; stringA.conca result.concat( concat(String
strings_string String result; t( stringB.con stringA, result+string A).concat(Stri
_buffer_NewQ Which of the following puts a reference to cat( stringC ) stringB, A+stringB+st ngB).concat(
B "Hello World Java" in result? MCQ ); stringC ); ringC; StringC) 1 0 0 0
For two string objects obj1 and obj2:
A) Use of obj1 == obj2 tests whether two
String object references refer to the same
strings_string object
_buffer_NewQ B) obj1.equals(obj2) compares the sequence Only A is Only B is Both A and B Both A and B
B of characters in obj1 and obj2. MCQ TRUE TRUE is TRUE is FALSE 0 0 1 0
What is the result of the following:

String ring = "One ring to rule them all,\n";


String find = "One ring to find them.";

if ( ring.startsWith("One") &&
find.startsWith("One") ) One ring to One ring to One ring to
strings_string System.out.println( ring+find ); rule them all, rule them all, rule them all,
_buffer_NewQ else One ring to One ring to \n One ring to Different
B System.out.println( "Different Starts" ); MCQ find them. find them. find them. Starts 1 0 0 0
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(st
String str2 ="str2"; r1) will not
String str3="str3"; result in a
str1.concat(str2); valid The program The program The program
strings_string System.out.println(str3.concat(str1)); argument for will print The program will print will print
_buffer_NewQ } the println() str3str1str2,w will print str3str1,when str3str2,when
B } MCQ method hen run str3,when run run run 0 0 0 1 0

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));

StringBuffer sb1 = new StringBuffer("abc");


StringBuffer sb2 = sb1;
sb1.append("d");
System.out.println(sb1 + " " + sb2 + " " +
(sb1==sb2)); The first line The second The second
strings_string } The first line of output is line of output line of output
_buffer_NewQ } Compilation of output is abcd abc is abcd abc is abcd abcd
B Which are true? (Choose all that apply.) MCA fails abc abc false false false true 0 0 0.5 0 0.5
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 Cognizant Cognizant Technology
B output from the options. MCQ Solutions Technology Solutions Solutions 0 0 1 0
What does this code write:

StringTokenizer stuff = new


strings_string StringTokenizer( "abc def+ghi", "+");
_buffer_NewQ System.out.println( stuff.nextToken() );
B System.out.println( stuff.nextToken() ); MCQ abc def abc def ghi abc def + abc def +ghi 0 1 0 0
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) {
StringBuffer sb = new
strings_string StringBuffer("antarctica"); Complies but
_buffer_NewQ sb.delete(0,6); Compilation exception at
B System.out.println(sb); }} MCQ tica anta error run time 1 0 0 0
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) {
strings_string String name="vikaramaditya";
_buffer_NewQ System.out.println(name.substring(2,
B 5).toUpperCase().charAt(2));}} MCQ K A R I 0 0 1 0
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) {
StringBuffer sb = new
StringBuffer("antarctica");
sb.reverse();
strings_string sb.replace(2, 7, "c");
_buffer_NewQ sb.delete(0,2);
B System.out.println(sb); }} MCQ acctna iccratna ctna tna 0 0 1 0
Consider the following code and choose the
correct option:
class Test {
public static void main(String args[]) {
String s1 = "abc";
strings_string String s2 = "def";
_buffer_NewQ String s3 = s1.concat(s2.toUpperCase( ) ); abcabcDEFD abcdefabcDE none of the
B System.out.println(s1+s2+s3); } } MCQ abcdefabcdef EF F listed options 0 0 1 0

What will be the result when you attempt to


compile and run the following code?.
public class Conv
{
public static void main(String argv[]){
Conv c=new Conv();
String s=new String("ello");
c.amethod(s);
}

public void amethod(String s){


char c='H';
c+=s; Compilation Compilation Compilation
strings_string System.out.println(c); and output and output and output
_buffer_NewQ } the string the string the string Compile time
B } MCQ "Hello" "ello" elloH error 0 0 0 1
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) {
strings_string String name="Anthony Gomes";
_buffer_NewQ System.out.println(name.replace('n', Compilation
B name.charAt(3)).compareTo(name)); }} MCQ -6 6 error 1 0 0 0
Consider the following code and choose the
correct option:
class Test {
public static void main(String args[]) {
String name=new String("batman");
int ibegin=1;
char iend=3;
strings_string System.out.println(name.substring(ibegin,
_buffer_NewQ iend)); Compilation
B }} MCQ bat at atm error 0 1 0 0
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) {
strings_string StringBuffer sb=new
_buffer_NewQ StringBuffer("YamunaRiver");
B System.out.println(sb.capacity()); }} MCQ 10 27 24 11 0 1 0 0
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) {
StringBuffer sb = new
StringBuffer("antarctica");
sb.reverse();
strings_string sb.insert(4, 'r');
_buffer_NewQ sb.replace(2, 4, "c");
B System.out.println(sb); }} MCQ acitcratna acitrcratna accircratna accrcratna 0 0 0 1
A)A string buffer is a mutable sequence of
strings_string characters.
_buffer_NewQ B) sequece of characters in the string buffer Only A is Only B is Both A and B Both A and B
B can not be changed. MCQ TRUE TRUE is TRUE is FALSE 1 0 0 0
Examine this code:

String stringA = "Wild";


String stringB = " Irish";
String stringC = " Rose"; result = result =
String result; stringA.conca result.concat( concat(String
strings_string t( stringB.con stringA, result+string A).concat(Stri
_buffer_NewQ Which of the following puts a reference to cat( stringC ) stringB, A+stringB+st ngB).concat(
B "Wild Irish Rose" in result? MCQ ); stringC ); ringC; StringC) 1 0 0 0
Consider the following code and choose the
correct option:
class Test {
public static void main(String[] args) {
new Test().display(1,"hi");
strings_string new Test().display(2,"hi", "world" ); }
_buffer_NewQ public void display(int x,String... s) { Compilation
B System.out.print(s[s.length-x] + " "); }} MCQ hi hi hi world world error 1 0 0 0
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) {
strings_string String name="vikaramaditya";
_buffer_NewQ System.out.println(name.codePointAt(2)+nam Compilation
B e.charAt(3)); }} MCQ 203 204 205 error 0 1 0 0
Consider the following code and choose the
correct option:
public class Test {
strings_string public static void main(String[] args) { Compiles but
_buffer_NewQ String data="7882"; exception at Compilation
B data+=32; System.out.println(data); }} MCQ 7914 run time 788232 error 0 0 1 0

Which code can be inserted at Line X to print


"Equal"?
public class EqTest{
public static void main(String argv[]){
EqTest e=new EqTest();
}

EqTest(){
String s="Java";
String s2="java";
// Line X
{
System.out.println("Equal");
}else
{
System.out.println("Not equal");
strings_string }
_buffer_NewQ } if(s.equals(s2 if(s.equalsIgn if(s.noCaseM if(s.equalIgnor
B } MCQ if(s==s2) )) oreCase(s2)) atch(s2)) eCase(s2)) 0 0 1 0 0

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
}
}

Which code fragment, inserted at line 15, will


IO_Operation allow Foo objects to be s.defaultWrite s.writeObject(
s_NewQB correctly serialized and deserialized? MCQ s.writeInt(x); s.serialize(x); Object(); x); 0 0 1 0
FileOutputStr
eam fos =
FileOutputStr FileOutputStr DataOutputSt new
eam fos = eam fos = ream dos = FileOutputStr
new new new eam( new
Which of the following opens the file FileOutputStr FileOutputStr DataOutputSt BufferedOutp
IO_Operation "myData.stuff" for output first deleting any file eam( "myDat eam( "myDat ream( "myDat utStream( "m
s_NewQB with that name? MCQ a.stuff", true ) a.stuff") a.stuff" ) yData.stuff") ) 0 1 0 0

import java.io.*;
public class MyClass implements Serializable
{

private Tree tree = new Tree();

public static void main(String [] args) {


MyClass mc= new MyClass();
try {
FileOutputStream fs = new
FileOutputStream(”MyClass.ser”);
ObjectOutputStream os = new A instance of
ObjectOutputStream(fs); MyClass and
os.writeObject(mc); os.close(); an instance
} catch (Exception ex) An exception An instance of Tree are
IO_Operation { ex.printStackTrace(); } Compilation is thrown at of MyClass is both
s_NewQB }} MCQ fails runtime serialized serialized 1 0 0 0

Consider the following code and choose the


correct option:
class std implements Serializable{
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
IO_Operation oos.close(); will be store Compilation error at run store to the
s_NewQB }} MCQ to file std.txt error time file. 1 0 0 0
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:/jlist.lst");
byte buffer[]=new byte[(int)file.length()+1]; reads data reads data
FileInputStream fis=new from file one from file
FileInputStream(file); byte at a time named
int ch=0; and display it jlist.lst in Compiles but
IO_Operation while((ch=fis.read())!=-1){ on the Compilation byte form and error at
s_NewQB System.out.print(ch); } }} MCQ console. error ascii value runtime 0 0 1 0

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:/jlist.lst"); reads data
byte buffer[]=new byte[(int)file.length()+1]; reads data from file
FileInputStream fis=new from file one named
FileInputStream(file); byte at a time jlist.lst in
int ch=0; and display it byte form and Compiles but
IO_Operation while((ch=fis.read())!=-1){ on the Compilation display error at
s_NewQB System.out.print((char)ch); } }} MCQ console. error garbage value runtime 1 0 0 0
Consider the following code and choose the
correct option:
public class Test { Compiles and
public static void main(String[] args) { creates Compiles but executes but
IO_Operation File file=new File("d:/prj/lib"); directory d:/ Compilation error at run directory is
s_NewQB file.mkdirs();}} MCQ prj/lib error time not created 1 0 0 0

Consider the following code and choose the


correct option:
public class Test {
public static void main(String[] args) throws
IOException {
String data="Confidential info";
byte buffer[]=data.getBytes();
FileOutputStream fos=new writes data to
FileOutputStream("d:/temp"); writes data to the file in Compiles but
IO_Operation for(byte d : buffer){ file in byte Compilation character error at
s_NewQB fos.write(d); } }} MCQ form. error form. runtime 1 0 0 0
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 Compilation
s_NewQB What is the result? MCQ ab abcd ab cd abcd Error 0 0 0 0 1

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
IO_Operation oos.close(); will be store Compilation error at run store to the
s_NewQB }} MCQ to file std.txt error time file. 0 0 1 0

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 reads data
FileInputStream fis=new from file from file
FileInputStream(file); named named
fis.read(buffer); jlist.lst in jlist.lst in
System.out.println(buffer); byte form and byte form and Compiles but
IO_Operation } display it on Compilation display error at
s_NewQB } MCQ console. error garbage value runtime 0 1 0 0
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) throws
IOException { reads data reads data
File file=new File("D:/jlist.lst"); from file from file
byte buffer[]=new byte[(int)file.length()+1]; named named
FileInputStream fis=new jlist.lst in jlist.lst in
FileInputStream(file); byte form and byte form and Compiles but
IO_Operation fis.read(buffer); display it on Compilation display error at
s_NewQB System.out.println(new String(buffer)); }} MCQ console. error garbage value runtime 1 0 0 0
throws a
What happens when the constructor for throws a throws a ArrayIndexOu
IO_Operation FileInputStream fails to open a file for DataFormatE FileNotFound tOfBoundsEx
s_NewQB reading? MCQ xception Exception ception returns null 0 1 0 0
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
IO_Operation File file=new File("d:/prj,d:/lib"); and lib in d: Compilation error at run are not
s_NewQB file.mkdirs();}} MCQ drive error time created 0 0 0 1

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
IO_Operation } I am a I am a Person I am Student I am
s_NewQB } MCQ Person Student a Student a Person 0 1 0 0
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");
IO_Operation D)FileReader fr = new FileReader("file.tst",
s_NewQB "UTF8"); MCQ A,D B,C C,D A,B 0 0 0 1
What is the DataOutputStream method that
IO_Operation writes double precision floating point values to
s_NewQB a stream? MCQ writeBytes() writeFloat() write() writeDouble() 0 0 0 1
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,
IO_Operation File newDir = new File("newDir"); directory named containing a containing a Compilation
s_NewQB dir.renameTo(newDir);} } MCQ named dir newDir file f1.txt file f1.txt error 0 0 0 1 0

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
IO_Operation FileWriter fw=new FileWriter("d:/temp.txt"); data to the Compilation error at transferred to
s_NewQB fw.write(new String(buffer));}} MCQ temp.txt error runtime the temp.txt 0 0 0 1

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 H|e| and print H|e| and then
IO_Operation "Hello". exception is l|l|o|Input l|l|o|End of terminate
s_NewQB Which statement about the program is true? MCQ not caught. error. stream. normally. 0 0 0 1
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
IO_Operation while((ch=reader.read())!=-1){ display it on Compilation runs without error at
s_NewQB System.out.print((char)ch); } }} MCQ console error output runtime 1 0 0 0
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
IO_Operation be the result of calling the method canWrite() ption is value false is value true is being none of the
s_NewQB on a File object representing this file? MCQ thrown returned returned writable. listed options 0 1 0 0 0
void add(int void add(int void add(int
Introduction_t x,int y) char char add(float x,int y) x,int y) void
o_OOPS_Ne Which of following set of functions are add(int x,int x) char char add(char sum(double
wQB example of method overloading MCQ y) add(float y) x,char y) x,double y) 0 0 1 0
Efficient avoiding
Introduction_t utilization of Code method name
o_OOPS_Ne What is the advantage of runtime memory at flexibility at confusion at
wQB polymorphism? MCQ runtime Code reuse runtime runtime 0 0 1 0
Introduction_t
o_OOPS_Ne Which of the following is an example of IS A Microprocess
wQB relationship? MCQ Ford - Car or - Computer Tea -Cup Driver -Car 1 0 0 0
Introduction_t
o_OOPS_Ne Which of the following is not a valid relation
wQB between classes? MCQ Inheritance Segmentation Instantiation Composition 0 1 0 0
Introduction_t
o_OOPS_Ne Which of the following is not an attribute of
wQB object? MCQ State Behaviour Inheritance Identity 0 0 0 1

You might also like