Core Java-Mcqs
Core Java-Mcqs
Core Java-Mcqs
Consider the following code and choose the MCQ Compiles and Compiles and Compiles and Compilation 0 0
correct option: display 2 runs without display 0 error
class X { int x; X(int x){x=2;}} any output
class Y extends X{ Y(){} void displayX(){
System.out.print(x);}
public static void main(String args[]){
new Y().displayX();}} 0 1
Consider the following code and choose the MCQ Compiles and Compiles and Compiles but Compilation 0 0
correct option: prints show() prints throws error
class Test{ private void display(){ Display() runtime
System.out.println("Display()");} show() exception
private static void show() { display();
System.out.println("show()");}
public static void main(String arg[]){
show();}} 0 1
Consider the following code and choose the MCQ Compilation Comiples and Compiles but Compiles and 0 1
correct option: error prints From A throws display 3
class A{ A(){System.out.print("From A");}} runtime
class B extends A{ B(int z){z=2;} exception
public static void main(String args[]){
new B(3);}} 0 0
class One{ MCQ 0,0 compiles compile error none of these 0 0
int var1; successfully
One (int x){ but runtime
var1 = x; error
}}
class Derived extends One{
int var2;
void display(){
System.out.println("var
1="+var1+"var2="+var2);
}}
class Main{
public static void main(String[] args){
Derived obj = new Derived();
obj.display();
}}
consider the code above & select the proper
output from the options. 1 0
Consider the following code and choose the MCQ code compiles code compiles j can not be compliation 0 0
correct option: fine and will but will not initialized error
package aj; class A{ protected int j; } display 23 display output
package bj; class B extends A
{ public static void main(String ar[]){
System.out.print(new A().j=23);}} 0 1
class Order{ MCQ compile error Man Dog Cat Dog Man Cat Cat Ant Dog 0 0
Order(){ Ant Ant Man
System.out.println("Cat");
}
public static void main(String... Args){
Order obj = new Order();
System.out.println("Ant");
}
static{
System.out.println("Dog");
}
{
System.out.println("Man");
}}
consider the code above & select the proper
output from the options. 1 0
public class MyAr { MCQ Unresolved Compilation None of the 0 1
public static void main(String argv[]) { compilation and output of given options
MyAr m = new MyAr(); problem: The null
m.amethod(); local variable
} i1 may not
public void amethod() { have been
final int i1; initialized
System.out.println(i1);
}
}
What is the Output of the Program? 0 0
class MyClass1 MCQ Compilation Runtime 2500 50 0 0
{ error Exception
private int area(int side)
{
return(side * side);
}
public static void main(String args[ ])
{
MyClass1 MC = new MyClass1( );
int area = MC.area(50);
System.out.println(area);
}
}
What would be the output? 1 0
class Sample MCQ 100 100 1 2 1 2 100 100 10 20 1 2 100 1 2 10 20 100 0 0
{int a,b; 10 20 10 20 100 100
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[])
{
Sample s1=new Sample (100);
}
}
What is the Output of the Program? 0 1
Consider the following code and choose the MCQ prints Hi Hello Compiler Runs but no Runtime Error 0 1
correct option: Error output
public class MyClass {
public static void main(String arguments[]) {
amethod(arguments);
}
public void amethod(String[] arguments) {
System.out.println(arguments[0]);
System.out.println(arguments[1]);
}
}
Command Line arguments - Hi, Hello 0 0
Given: MCQ int Long Short Long Compilation An exception 1 0
public class Yikes { fails. is thrown at
runtime.
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;
go(y);
go(z);
}
}
What is the result? 0 0
abstract class MineBase { MCQ A Sequence A Sequence IndexOutOfBo Compilation 0 0
abstract void amethod(); of 5 zero's will of 5 one's will undes Error Error occurs
static int i; be printed like be printed like and to avoid
} 00000 11111 them we need
public class Mine extends MineBase { to declare
public static void main(String argv[]){ Mine class as
int[] ar=new int[5]; abstract
for(i=0;i < ar.length;i++)
System.out.println(ar[i]);
}
} 0 1
What will be the result when you attempt to MCQ Compile time A random A random A compile 1 0
compile this program? error referring number number time error as
public class Rand{ to a cast between 1 between 0 random being
public static void main(String argv[]){ problem and 10 and 1 an undefined
int iRand; method
iRand = Math.random();
System.out.println(iRand);
}
} 0 0
Which of the following declarations are MCA boolean b = byte b = 256; String s = int i = new 0 0
correct? (Choose TWO) TRUE; “null”; Integer(“56”); 0.5 0.5
class A, B and C are in multilevel inheritance MCQ Constructor of Constructor of Constructor of Constructor of 1 0
hierarchy repectively . In the main method of A executes C executes C executes A executes
some other class if class C object is created, in first, followed first followed first followed first followed
what sequence the three constructors execute? by the by the by the by the
constructor of constructor of constructor of constructor of
B and C A and B B and A C and B 0 0
What will be the result when you try to compile MCQ 200 100 followed Compile time 100 0 0
and run the following code? by 200 error
private class Base{
Base(){
int i = 100;
System.out.println(i);
}
}
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;
public Sandwich() {
System.out.println("Sandwich()");
}
}
public class MyClass7 {
public static void main(String[] args) { 0 0
new Sandwich();
Consider the following code and choose the MCQ compiles and compilation Compiles and Compiles and 1 0
correct option: display 0 error display 4 display 3
class A{ int a; A(int a){a=4;}}
class B extends A{ B(){super(3);} void
displayA(){
System.out.print(a);}
public static void main(String args[]){
new B().displayA();}} 0 0
class Order{ MCQ Cat Ant Dog Dog Cat Ant Ant Cat Dog none 0 1
Order(){
System.out.println("Cat");
}
public static void main(String... Args){
Order obj = new Order();
System.out.println("Ant");
}
static{
System.out.println("Dog");
}}
consider the code above & select the proper
output from the options. 0 0
What will happen if a main() method of a MCQ The compiler The compiler The program The program 0 1
"testing" class tries to access a private instance will will find the will compile will compile
variable of an object using dot notation? automatically error and will and run successfully,
change the not make a successfully but the .class
private .class file file will not run
variable to a correctly
public variable
0 0
What will be the result of compiling the MCQ The program A compilation A compilation A compilation 1 0
following program? will compile error will error will error will
public class MyClass { without errors. occur at (Line occur at (Line occur at (2),
long var; no 2), since no 1), since since the
public void MyClass(long param) { var = the class does constructors class does not
param; } // (Line no 1) not have a cannot specify have a default
public static void main(String[] args) { constructor a return value constructor
MyClass a, b; that takes one
a = new MyClass(); // (Line no 2) argument of
} type int.
} 0 0
public class MyClass { MCQ String: String int: 27, String: Compilation Runtime 1 0
static void print(String s, int i) { first, int: 11 Int first String: Error Exception
System.out.println("String: " + s + ", int: " + i); int: 99, String: String first, int:
} Int first 27
0 0
Here is the general syntax for method MCQ The If the The The 0 0
definition: returnValue returnType is returnValue returnValue
can be any void then the must be the must be
accessModifier returnType methodName( type, but will returnValue same type as exactly the
parameterList ) be can be any the same type as
{ automatically type returnType, or the
Java statements converted to be of a type returnType.
returnType that can be
return returnValue; when the converted to
} method returnType
returns to the without loss of
caller information
What is true for the returnType and the
returnValue? 1 0
11. class Mud { MCQ 3 1 2 1 0
12. // insert code here
13. System.out.println("hi");
14. }
15. }
And the following five fragments:
public static void main(String...a) {
public static void main(String.* a) {
public static void main(String... a) {
public static void main(String[]... a) {
public static void main(String...[] a) {
How many of the code fragments, inserted
independently at line 12, compile? 0 0
package QB; MCQ methodRadius sp.methodRa Nothing to add Sphere.metho 0 1
class Sphere { (x); dius(x); dRadius();
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;
Sphere sp = new Sphere();
// Some code missing
}
} to get the radius value what is the code of line
to be added ? 0 0
A) A call to instance method can not be made MCQ Only B is Only A is Both are Both are 0 0
from static context. TRUE TRUE TRUE FALSE
B) A call to static method can be made from
non static context. 1 0
Consider the following code and choose the MCQ Compiles and Compiles and Compilation Compiles but 0 0
correct option: displays Hi throws run fails doesn't
class A{ private void display(){ time exception display
System.out.print("Hi");} anything
public static void main(String ar[]){
display();}} 1 0
class One{ MCQ var1=10 , 0,0 compile error runtime error 1 0
int var1; var2=10
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){
Derived obj = new Derived();
obj.display();
}}
consider the code above & select the proper
output from the options. 0 0
public class MyAr { MCQ Compile time Compilation It is not 0 0
public static void main(String argv[]) { error because and output of possible to
MyAr m = new MyAr(); i has not been null declare a
m.amethod(); initialized static variable
} in side of non
public void amethod() { static method
static int i1; or instance
System.out.println(i1); method.
} Because
} Static
What is the Output of the Program? variables are
class level
dependencies.
0 1
Consider the following code and choose the MCQ Compilation Compiles but Compiles and None of the 1 0
correct option: error throws run displays listed options
class A{ int z; A(int x){z=x;} } time exception nothing
class B extends A{
public static void main(String arg){
new B();}} 0 0
A) No argument constructor is provided to all MCQ Only A is All are TRUE B and C is All are FALSE 0 0
Java classes by default TRUE TRUE
B) No argument constructor is provided to the
class only when no constructor is defined.
C) Constructor can have another class object
as an argument
D) Access specifiers are not applicable to
Constructor
1 0
Which modifier is used to control access to MCQ default public transient synchronized 0 0
critical code in multi-threaded programs? 0 1
public class c1 { MCQ Hello It is not Compilation Can't create 1 0
private c1() possible to Error object
{ declare a because
System.out.println("Hello"); constructor constructor is
} private private
public static void main(String args[])
{
c1 o1=new c1();
}
}
0 0 1
Choose the correct declaration of variable in an MCQ public final static data static final final data type 1 0
interface: data type type variable; data type variablename
varaibale=inti varaiblename; =intialization;
alization; 0 0
Given: MCA p0 = p1; p2 = p4; p1 = p1 = p2; 0.5 0
11. class ClassA {} (ClassB)p3;
12. class ClassB extends ClassA {}
13. class ClassC extends ClassA {}
and:
21. ClassA p0 = new ClassA();
22. ClassB p1 = new ClassB();
23. ClassC p2 = new ClassC();
24. ClassA p3 = new ClassB();
25. ClassA p4 = new ClassC();
Which TWO are valid? (Choose two.) 0.5 0
Consider the following code and choose the MCQ Hello A Compilation Hello B Compiles but 0 0
correct option: error error at
class A{ runtime
void display(){ System.out.println("Hello A"); }}
class B extends A{
void display(){
System.out.println("Hello B"); }}
public class Test {
public static void main(String[] args) {
B b=(B) new A();
b.display(); }}
0 1
A class Animal has a subclass Mammal. Which MCQ Because of Because of Because of Because of 0 1
of the following is true: single single single single
inheritance, inheritance, inheritance, inheritance,
Mammal can Mammal can Animal can Mammal can
have no have no other have only one have no
subclasses parent than subclass siblings.
Animal 0 0
Given: MCQ s 14 s 16 s 10 Compilation 0 0
interface DeclareStuff { fails.
public static final int Easy = 3;
void doStuff(int t); }
public class TestDeclare implements
DeclareStuff {
public static void main(String [] args) {
int x = 5;
new TestDeclare().doStuff(++x);
}
void doStuff(int s) {
s += Easy + ++s;
System.out.println("s " + s);
}
} What is the result? 0 1
Consider the following code and choose the MCQ A Compilation Compiles but Runs but no 0 1
correct option: error error at run output
interface console{ time
int line=10;
void print();}
class a implements console{
void print(){
System.out.print("A");}
public static void main(String ar[]){
new a().print();}} 0 0
Which of the following is correct for an abstract MCA An abstract An abstract An abstract Abstract class 0.5 0.5
class. (Choose TWO) class is one class is one class is one can be
which which which declared final
contains contains some contains only
general defined static methods
purpose methods and
methods some
undefined
methods 0 0
Which declaration can be inserted at (1) MCA int total = total final double protected int int AREA = r * public static 0 0.5
without causing a compilation error? + r + s; circumference CODE = s; MAIN = 15;
interface MyConstants { = 2 * Math.PI * 31337;
int r = 42; r;
int s = 69;
// (1) INSERT CODE HERE
} 0 0.5 0
Given : MCQ No—there No—but a Yes—an Yes—any 0 0
must always object of object can be object can be
Day d; be an exact parent type assigned to a assigned to
BirthDay bd = new BirthDay("Raj", 25); match can be reference any reference
d = bd; // Line X between the assigned to a variable of the variable.
variable and variable of parent type.
Where Birthday is a subclass of Day. State the object child type.
whether the code given at Line X is correct: 1 0
class Animal { MCQ run time error generic noise bark compile error 0 0
void makeNoise() {System.out.println("generic
noise"); }
}
class Dog extends Animal {
void makeNoise() {System.out.println("bark"); }
void playDead() { System.out.println("roll
over"); }
}
class CastTest2 {
public static void main(String [] args) {
Animal a = new Dog();
a.makeNoise();
}
}
consider the code above & select the proper
output from the options.
1 0
interface Vehicle{ MCQ Auto Bicycle Auto compile error runtime error 0 0
void drive();
}
final class TwoWheeler implements Vehicle{
int wheels = 2;
public void drive(){
System.out.println("Bicycle");
}
}
class ThreeWheeler extends TwoWheeler{
public void drive(){
System.out.println("Auto");
}}
class Test{
public static void main(String[] args){
ThreeWheeler obj = new ThreeWheeler();
obj.drive();
}}
consider the code above & select the proper
output from the options. 1 0
Select the correct statement: MCQ Private A subclass An overriding The The overriding 1 0
methods can override method can parameter list method must
cannot be any method in declare that it of an have different
overridden in a superclass throws overriding return type as
subclasses checked method can the overridden
exceptions be a subset of method
that are not the parameter
thrown by the list of the
method it is method that it
overriding is overriding
0 0 0
Consider the code below & select the correct MCQ 3 Compilation Compiles but 9 0 1
ouput from the options: error error at run
class A{ time
static int sq(int n){
return n*n; }}
public class Test extends A{
static int sq(int n){
return super.sq(n); }
public static void main(String[] args) {
System.out.println(new Test().sq(3)); }} 0 0
Given: MCQ No—a No—a No—a Yes—the 0 0
public static void main( String[] args ) { variable must variable must variable must variable can
SomeInterface x; ... } always be an always be an always be a refer to any
Can an interface name be used as the type of a object object primitive type object whose
variable reference type reference type class
or a primitive implements
type the interface 0 1
Given : MCQ The code will The code will The code will The code will 0 0
What would be the result of compiling and fail to compile fail to compile compile and compile and
running the following program? because the because a call print 23, when print 29, when
// Filename: MyClass.java max() method to a max() run. run.
public class MyClass { in B passes method is
public static void main(String[] args) { the arguments ambiguous.
C c = new C(); in the call
System.out.println(c.max(13, 29)); super.max(y,
} x) in the
} wrong order.
class A {
int max(int x, int y) { if (x>y) return x; else return
y; }
}
class B extends A{
int max(int x, int y) { return super.max(y, x) -
10; }
}
class C extends B {
int max(int x, int y) { return super.max(x+10,
y+10); }
} 0 1
Given: MCQ Compilation If you define D Compilation If you define D 0 1
interface A { public void methodA(); } fails, due to an e = (D) (new fails, due to an e = (D) (new
interface B { public void methodB(); } error in line 3 E()), then error in line 7 E()), then
interface C extends A,B{ public void e.methodB() e.methodB()
methodC(); } //Line 3 invokes the invokes the
class D implements B { version of version of
public void methodB() { } //Line 5 methodB() methodB()
} defined at line defined at line
class E extends D implements C { //Line 7 9 5
public void methodA() { }
public void methodB() { } //Line 9
public void methodC() { }
}
What would be the result? 0 0
Select the correct statement: MCQ A super() or If both a If neither If super() is Calling 0 1
this() call subclass and super() nor the first super() as the
must always its superclass this() is statement in first statement
be provided do not have declared as the body of a in the body of
explicitly as any declared the first constructor, a constructor
the first constructors, statement in this() can be of a subclass
statement in the implicit the body of a declared as will always
the body of a default constructor, the second work, since all
constructor. constructor of this() will statement superclasses
the subclass implicitly be have a default
will call inserted as constructor.
super() when the first
run statement.
0 0 0
class Animal { MCQ run time error generic noise bark compile error 1 0
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();
a.makeNoise();
}
}
consider the code above & select the proper
output from the options.
0 0
Consider the code below & select the correct MCQ Canada Compilation Compiles but null 0 1
ouput from the options: error error at run
time
class Money {
private String country = "Canada";
public String getC() { return country; } }
class Yen extends Money {
public String getC() { return super.country; }
public static void main(String[] args) {
System.out.print(new Yen().getC() ); } } 0 0
Which Man class properly represents the MCQ A B C D 0 0
relationship "Man has a best friend who is a
Dog"?
A)class Man extends Dog { }
B)class Man implements Dog { }
C)class Man { private BestFriend dog; }
D)class Man { private Dog bestFriend; } 0 1
Consider the following code and choose the MCQ display Compilation Compiles but Runs but no 0 1
correct option: error error at run output
interface Output{ time
void display();
void show();
}
class Screen implements Output{
void show() {System.out.println("show");}
void display(){ System.out.println("display");
}public static void main(String[] args) {
new Screen().display();}}
0 0
The concept of multiple inheritance is MCQ (A) (A) & (C) (D) (B) & (C) 0 0
implemented in Java by
class B extends A {
public void doSomething() throws
SomeException { }
} 0 1
Given: MCQ This is a final This is a final Compilation illegal Some 0 0
class A { method illegal method Some error error
final void meth() { error message
System.out.println("This is a final method."); message
}
}
class B extends A {
void meth() {
System.out.println("Illegal!");
}
}
class MyClass8{
public static void main(String[] args) {
A a = new A();
a.meth();
B b= new B();
b.meth();
}
}What would be the result?
1 0
Consider the code below & select the correct MCQ 000 47 7 0 Compilation 47 47 47 0 0
ouput from the options: error
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) {
Cd cd=new Cd();
Bc bc=new Cd();
Ab ab=new Cd();
System.out.println(cd.getN()+" "+
bc.getN()+" "+ab.getN()); }}
0 1
Given: MCQ class AllMath interface abstract class class AllMath 0 0
interface DoMath extends AllMath AllMath implements
{ DoMath { implements implements MathPlus {
double getArea(int r); double MathPlus { DoMath, double
} getArea(int r); double MathPlus { getArea(int
interface MathPlus } getVol(int x, public double rad); }
{ int y); } getArea(int
double getVolume(int b, int h); rad) { return
} rad * rad *
/* Missing Statements ? */ 3.14; } }
Select the correct missing statements. 1 0
interface interface_1 { MCQ From F1 Compile time Create an Runtime Error 0 1
void f1(); function in error object for
} Class_1 Class Interface only
class Class_1 implements interface_1 {
void f1() {
System.out.println("From F1 funtion in
Class_1 Class");
}
}
public class Demo1 {
public static void main(String args[]) {
Class_1 o11 = new Class_1();
o11.f1();
}
} 0 0
interface A{} MCQ B b=c; A a2=(B)c; C c2=(C)(B)c; A a1=(Test)c; 0 0
class B implements A{}
class C extends B{}
public class Test extends C{
public static void main(String[] args) {
C c=new C();
/* Line6 */}}
1 0
Consider the code below & select the correct MCQ 100 Compilation Compiles but Compiles but 1 0
ouput from the options: error error at run no output
time
class Mountain{
int height;
protected Mountain(int x) { height=x; }
public int getH(){return height;}}
0.5 0 0
Which collection class allows you to grow or MCQ java.util.Hash java.util.Linke java.util.List java.util.Array java.util.Vecto 0 0
shrink its size and provides indexed access to Set dHashSet List r
its elements, but its methods are not
synchronized?
0 1 0
Which statement is true about the following MCQ The program The program The program The program 0 0
program? will compile will compile will compile will not
import java.util.ArrayList; and print the and print the and throw a compile
import java.util.Collections; following following runtime
import java.util.List; output: [B] output: [B,A] exception
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())
;
System.out.println(list.subList(1,2));
}
} 1 0
static int binarySearch(List list, Object key) is a MCQ Vector class ArrayList Collection Collections 0 0
method of __________ class interface class 0 1
Given: MCQ 1 12 14 123 0 0
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]);
}
} What is the result? 1 0
static void sort(List list) method is part of MCQ Collection Collections Vector class ArrayList 0 1
________ interface class class 0 0
Consider the code below & select the correct MCQ 2 -4 3 -5 2 -6 3 -4 0 0
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");
int s2=Arrays.binarySearch(colors, "silver");
System.out.println(s1+" "+s2); }}
1 0
Consider the following code was executed on MCQ Wed Jun 01 244 JUN 01 PST JUN 01 GMT JUN 01 1 0
June 01, 1983. What will be the output? 1983 1983 1983 1983
class Test{
public static void main(String args[]){
Date date=new Date();
SimpleDateFormat sd;
sd=new SimplpeDateFormat("E MMM dd
yyyy");
System.out.print(sd.format(date));}} 0 0
Consider the following code and choose the MCQ 3 5 compilation Compiles but 0 1
correct option: error error at run
class Data{ Integer data; Data(Integer time
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));
s.add(new Data(2));
System.out.print(s.size());}} 0 0
next() method of Scanner class will return MCQ Integer Long int String 0 0
_________ 0 1
Given: MCQ 3, 2, 1, 1, 2, 3, Compilation The code runs 0 0
public static Iterator reverse(List list) { fails. with no
Collections.reverse(list); output.
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 + ", ");
}
What is the result? 1 0
Given: MCQ true false Compile time Runtime 0 1
import java.util.Arrays; error Exception
import java.util.HashSet;
import java.util.Set;
System.out.println(set.equals(set2));
}
} What is the result of given code?
0 0
import java.util.StringTokenizer; MCQ Today is Today is Both none of the 0 1
class ST{ Holiday Holiday listed options
public static void main(String[] args){
String input = "Today is$Holiday";
StringTokenizer st = new
StringTokenizer(input,"$");
while(st.hasMoreTokens()){
System.out.println(st.nextElement());
}} 0 0
int indexOf(Object o) - What does this method MCQ null -1 none of the 0 1
return if the element is not found in the List? listed options
0 0
Consider the following code and choose the MCQ Compilation prints 3,4,2,1, prints 1,2,3,4 Compiles but 0 0
correct option: error exception at
class Test{ runtime
public static void main(String args[]){
Integer arr[]={3,4,3,2};
Set<Integer> s=new
TreeSet<Integer>(Arrays.asList(arr));
s.add(1);
for(Integer ele :s){
System.out.println(ele); } }} 1 0
A) It is a good practice to store heterogenous MCQ A and B is A and D is A and C is B and C is 0 0
data in a TreeSet. TRUE TRUE TRUE TRUE
B) HashSet has default initial capacity (16) and
loadfactor(0.75)
C)HashSet does not maintain order of
Insertion
D)TreeSet maintains order of Inserstion 0 1
Consider the following code and choose the MCQ [1,4,6,8] [1,8,6,4] [1,4,6,8,9] [1,4,6,8,9] 0 0
correct option: [4,6,8,9] [8,6,4,9] [4,6,8,9] [4,6,8]
class Test{
public static void main(String args[]){
TreeSet<Integer> ts=new
TreeSet<Integer>();
ts.add(1);
ts.add(8);
ts.add(6);
ts.add(4);
SortedSet<Integer> ss=ts.subSet(2, 10);
ss.add(9);
System.out.println(ts);
System.out.println(ss);
}} 1 0
Inorder to remove one element from the given MCQ tSet.clear(new tSetdelete(ne tSet.remove(n tSet.drop(new 0 0
Treeset, place the appropriate line of code Integer("1")); w ew Integer("1"));
public class Main { Integer("1")); Integer("1"));
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());
}
}
1 0
A)Property files help to decrease coupling MCQ A and B is A and D is A and C is B and D is 0 0
B) DateFormat class allows you to format dates TRUE TRUE TRUE TRUE
and times with customized styles.
C) Calendar class allows to perform date
calculation and conversion of dates and times
between timezones.
D) Vector class is not synchronized 1 0
Which interface does java.util.Hashtable MCQ Java.util.Map Java.util.List Java.util.Table Java.util.Colle 1 0
implement? ction 0 0
Consider the following code and choose the MCQ The before() The before() The before() The before() 0 0
correct option: method will method will method will method will
public static void before() { print 1 2 print 1 2 3 throw an not compile
Set set = new TreeSet(); exception at
set.add("2"); runtime
set.add(3);
set.add("1");
Iterator it = set.iterator();
while (it.hasNext())
System.out.print(it.next() + " ");
} 1 0
Given: MCQ Compilation aAaA aAa AAaa AaA AaA AAaa 0 0
import java.util.*; fails. AAaa AaA aAa aAaA aAaA aAa
1) TreeSet
2) HashMap
3) LinkedList
4) an array 0 1
Given: MCQ Compilation The code runs An exception Compilation Compilation 1 0
10. interface A { void x(); } fails because with no is thrown at fails because fails because
11. class B implements A { of an error in output. runtime of an error in of an error in
public void x() { } line 25 line 21 line 23.
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();
25. a.y();;
26. }
What is the result? 0 0 0
A) Iterator does not allow to insert elements MCQ A and B is A and D is A and C is B and D is 0 0
during traversal TRUE TRUE TRUE TRUE
B) Iterator allows bidirectional navigation.
C) ListIterator allows insertion of elements
during traversal
D) ListIterator does not support bidirectional
navigation 1 0
What will be the output of following code? MCQ [2,3,7,5] [2,3,4,5,6] [2,3,7,5,4,6] [2,3,4,5,6,7] 0 1
class Test{
public static void main(String args[]){
TreeSet<Integer> ts=new TreeSet<Integer>();
ts.add(2);
ts.add(3);
ts.add(7);
ts.add(5);
SortedSet<Integer> ss=ts.subSet(1,7);
ss.add(4);
ss.add(6);
System.out.print(ss);}}
0 0
Object get(Object key) - What does this MCQ -1 null none of the 0 0
method return if the key is not found in the listed options
Map? 1 0
Consider the following code and choose the MCQ {2=Two, {4=Four, {4=Four, {2=Two, 0 0
correct output: 4=Four, 6=Six, 6=Six} 4=Four,
class Test{ 6=Six, 7=Seven} 6=Six}
public static void main(String args[]){ 7=Seven}
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>
sm2=sm.tailMap(4);
System.out.print(sm2);
}} 1 0
Which of the given options is similar to the MCQ value = value sum = sum + value = value value = value 1 0
following code: + sum; sum = 1; value = + sum; + ++sum;
sum + 1; value + sum;
value += sum++ ; 0 0
Which will legally declare, construct, and MCQ int [] myList = int [] myList = int myList [] [] int myList [] = 0 0
initialize an array? {"1", "2", "3"}; (5, 8, 2); = {4,9,7,0}; {4, 3, 7};
0 1
Consider the code below & select the correct MCQ Compilation The variable The variable Compiles but 0 0
ouput from the options: error first is set to first is set to error at
public class Test { null. elements[0]. runtime
public static void main(String[] args) {
String[] elements = { "for", "tea", "too" };
String first = (elements.length > 0)
?elements[0] : null;
System.out.println(first); }} 1 0
Consider the following code and choose the MCQ Hello World Compilation Compiles but Compiles but 1 0
correct option: error error at run run without
class Test{ time output
interface Y{
void display(); }
public static void main(String[] args) {
new Y(){
public void display(){
System.out.println("Hello World"); }
}.display(); }} 0 0
class Test{ MCQ 48 94 Compiles but Compilation 0 1
public static void main(String[] args){ error at run error
byte b=(byte) (45 << 1); time
b+=4;
System.out.println(b); }}
What should be the output for the code written
above? 0 0
What is the value of y when the code below is MCQ 1 2 3 4 0 0
executed?
int a = 4;
int b = (int)Math.ceil(a % 3 + a / 3.0); 1 0
Consider the following code and choose the MCQ Hello World Compilation Compiles but Compiles but 1 0
correct option: error error at run run without
class Test{ time output
interface Y{
void display(); }
public static void main(String[] args) {
Y y=new Y(){
public void display(){
System.out.println("Hello World"); } };
y.display(); }} 0 0
What is the output of the following program? MCQ A sequence of A sequence of compile time Compiles but 0 0
public class demo { five 10's are Garbage Error no output
public static void main(String[] args) { printed Values are
int arr[5]; printed
for (int i = 0; i < arr.length; i++) {
arr[i] = arr[i] + 10;
}
for (int j = 0; j < arr.length; j++)
System.out.println(arr[j]);
}
} 1 0
What will be the result of the following MCQ The program The program The program The program Compilation 0 0
program? will compile, will compile, will compile, will compile, error
public class Init { and print and print and print | and print
String title; |null|false|0|0. |null|true|0|0.0| |false|0|0.0|0.0 |null|false|0|0.
boolean published; 0|0.0|, when 100.0|, when |, when run 0|100.0|, when
static int total; run run run
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 + "|" +
initMe.published + "|" +
Init.total + "|" + Init.maxPrice + "|" + price+ "|");
}
}
0 1 0
Consider the following code and choose the MCQ 4 Compilation Compiles but 1 0
correct option: error error at run
class Test{ time
static class A{
interface X{
int z=4; } }
static void display(){
System.out.println(A.X.z); }
public static void main(String[] args) {
display(); }} 0 0
Here is the general syntax for method MCQ The The If the The 0 0
definition: returnValue returnValue returnType is returnValue
must be can be any void then the must be the
accessModifier returnType methodName( exactly the type, but will returnValue same type as
parameterList ) same type as be can be any the
{ the returnType automatically type returnType, or
Java statements converted to be of a type
returnType that can be
return returnValue; when the converted to
} method returnType
returns to the without loss of
caller. information.
What is true for the returnType and the
returnValue? 0 1
class C{ MCQ compile time compile time prints 34,56 runtime none of the 0 1
public static void main (String[] args) { error at line 2 error at line 4 exception listed options
byte b1=33; //1
b1++; //2
byte b2=55; //3
b2=b1+1; //4
System.out.println(b1+""+b2);
}}
Consider the code above & select the correct
output. 0 0 0
What will be the output of the program? MCQ args[2] = 2 args[2] = 3 args[2] = null An exception 0 0
is thrown at
public class CommandArgs runtime
{
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);
}
}
int value = 0;
int count = 1;
value = count++ ;
System.out.println("value: "+ value + " count: "
+ count); 0 1
What will be the output of the program? MCQ 012 23 000 An exception 0 0
is thrown at
public class CommandArgsTwo runtime
{
public static void main(String [] argh)
{
int x;
x = argh.length;
for (int y = 1; y <= x; y++)
{
System.out.print(" " + argh[y]);
}
}
}
int a = 0;
int b = 10;
a = --b ;
System.out.println("a: " + a + " b: " + b ); 1 0
Consider the given code and select the correct MCQ 26 282 Compiles but Compilation 0 1
output: error at run error
class Test{ time
public static void main(String[] args){
int num1 = 012;
int num2 = 0x110;
int sum =num1+=num2;
System.out.println("Ans = "+sum); }} 0 0
What will happen if you attempt to compile and MCQ 19 followed by 19 follwed by Compile time 10 followed by 1 0
run the following code? 11 20 error 1
Integer ten=new Integer(10);
Long nine=new Long (9);
System.out.println(ten + nine);
int i=1;
System.out.println(i + ten); 0 0
Which of the following are correct variable MCA int #ss; int 1ah; int _; int $abc; 0 0
names? (Choose TWO) 0.5 0.5
Which of the following lines of code will MCQ Line 1, Line 5 Line 5 Line 1, Line 3, Line 3 Line 4 0 1
compile without warning or error? Line 5
1) float f=1.3;
2) char c="a";
3) byte b=257;
4) boolean b=null;
5) int i=10; 0 0 0
Consider the code below & select the correct MCQ 23 13 2 3 1 0
ouput from the options:
class Accounts
{
public double calculateBonus(){//method's
code}
} 1 0
Say that class Rodent has a child class Rat and MCQ rod = mos pkt = rat pkt = null rod = rat 0 1
another child class Mouse. Class Mouse has a
child class PocketMouse. Examine the
following
Rodent rod;
Rat rat = new Rat();
Mouse mos = new Mouse();
PocketMouse pkt = new PocketMouse();
EqTest(){
String s="Java";
String s2="java";
// Line X
{
System.out.println("Equal");
}else
{
System.out.println("Not equal");
}
}
} 1 0 0
Given: MCA Compilation The first line The first line The second The second 0 0
public class Theory { fails of output is of output is line of output line of output
public static void main(String[] args) { abc abc false abcd abc false is abcd abc is abcd abcd
String s1 = "abc"; false true
String s2 = s1;
s1 += "d";
System.out.println(s1 + " " + s2 + " " +
(s1==s2));
if ( ring.startsWith("One") &&
find.startsWith("One") )
System.out.println( ring+find );
else
System.out.println( "Different Starts" ); 0 0
Consider the following code and choose the MCQ -6 6 Compilation 1 0
correct option: error
public class Test {
public static void main(String[] args) {
String name="Anthony Gomes";
System.out.println(name.replace('n',
name.charAt(3)).compareTo(name)); }} 0 0
Consider the following code and choose the MCQ The code will The program The program The program The program 0 0
correct option: fail to compile will print will print will print will print
class MyClass { because the str3str1str2,w str3,when run str3str1,when str3str2,when
String str1="str1"; expression hen run run run
String str2 ="str2"; str3.concat(str
String str3="str3"; 1) will not
str1.concat(str2); result in a
System.out.println(str3.concat(str1)); valid
} argument for
} the println()
method 0 1 0
Consider the following code and choose the MCQ tica anta Compilation Complies but 1 0
correct option: error exception at
public class Test { run time
public static void main(String[] args) {
StringBuffer sb = new
StringBuffer("antarctica");
sb.delete(0,6);
System.out.println(sb); }} 0 0
Consider the following code and choose the MCQ 788232 7914 Compilation Compiles but 1 0
correct option: error exception at
public class Test { run time
public static void main(String[] args) {
String data="7882";
data+=32; System.out.println(data); }} 0 0
class X2 MCQ 1 2 3 0 0
{
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 */
}
}
int count = 1;
while ( ___________ )
{
System.out.print( count + " " );
count = count + 1;
}
System.out.println( );
12345678 0 0
Given: MCQ 2 24 234 246 0 1
public class Breaker2 {
static String o = "";
public static void main(String[] args) {
z:
for(int x = 2; x < 7; x++) {
if(x==3) continue;
if(x==5) break z;
o = o + x;
}
System.out.println(o);
}
}
What is the result? 0 0
Consider the following code and choose the MCQ Compilation 1515 255 Compiles but 0 0
correct option: error error at run
class Test{ time
public static void main(String args[]){
String hexa = "0XFF";
int number = Integer.decode(hexa);
System.out.println(number); }} 1 0
Given: MCQ Compilation granite granite atom granite atom granite 0 0
class Atom { fails. granite atom granite
Atom() { System.out.print("atom "); }
}
class Rock extends Atom {
Rock(String type) { System.out.print(type); }
}
public class Mountain extends Rock {
Mountain() {
super("granite ");
new Rock("granite ");
}
public static void main(String[] a) { new
Mountain(); }
}
What is the result? 0 1
Which of the following statements about arrays MCQ Person[] p []; Person p[][] = Person[] p = Person p[5]; 0 0
is syntactically wrong? new new
Person[2][]; Person[5]; 0 1
Given: MCQ hi hi hi world world world Compilation 0 0
public class Barn { fails.
public static void main(String[] args) {
new Barn().go("hi", 1);
new Barn().go("hi", "world", 2);
}
public void go(String... y, int x) {
System.out.print(y[y.length - 1] + " ");
}
}
What is the result? 0 1
Given: MCQ 23 32 25 Compilation Runtine Error 0 0
int n = 10; Error
switch(n)
{
case 10: n = n + 1;
case 15: n = n + 2;
case 20: n = n + 3;
case 25: n = n + 4;
case 30: n = n + 5;
}
System.out.println(n);
What is the value of ’n’ after executing the
following code? 1 0 0
Given: MCQ 00 0001 000120 00012021 0 0
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;
}
}
System.out.println(o);
}
What is the result when the go() method is
invoked? 1 0
What will be the output of the program? MCQ 012 012122 Compilation Compilation 0 0
fails at line 11 fails at line 12.
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 */
case x: System.out.print("2 "); /*
Line 13 */
}
}
}
} 1 0
Consider the following code and choose the MCQ Compilation Compiles but Five Three 1 0
correct output: error no output
class Test{
public static void main(String args[]){
int a=5;
if(a=3){
System.out.print("Three");}else{
System.out.print("Five");}}} 0 0
public void foo( boolean a, boolean b) MCQ If a is true and If a is true and If a is false If a is false 0 0
{ b is false then b is true then and b is false and b is true
if( a ) the output is the output is then the then the
{ "notB" "A && B" output is output is
System.out.println("A"); /* Line 5 */ "ELSE" "ELSE"
}
else if(a && b) /* Line 7 */
{
System.out.println( "A && B");
}
else /* Line 11 */
{
if ( !b )
{
System.out.println( "notB") ;
}
else
{
System.out.println( "ELSE" ) ;
}
}
}
0 0
Consider the code below & select the correct MCQ 0001 000120 00012021 Compilation 0 1
ouput from the options: error
public class Test{
public static void main(String[] args) {
String num="";
z: for(int x=0;x<3;x++)
for(int y=0;y<2;y++){
if(x==1) break;
if(x==2 && y==1) break z;
num=num+x+y;
}System.out.println(num);}} 0 0
What will be the output of the program? MCQ x=1 x=3 Compilation The code runs 0 0
int x = 3; fails. with no
int y = 1; output.
if (x = y) /* Line 3 */
{
System.out.println("x =" + x);
} 1 0
Given: MCQ r, t, t, r, e, o, Compilation An exception 0 0
public static void test(String str) { fails. is thrown at
int check = 4; runtime.
if (check = str.length()) {
System.out.print(str.charAt(check -= 1) +", ");
} else {
System.out.print(str.charAt(0) + ", ");
}
}
and the invocation:
test("four");
test("tee");
test("to");
What is the result?
1 0
Which collection implementation is suitable for MCQ TreeMap HashSet Vector LinkedList ArrayList 0 0
maintaining an ordered sequence of
objects,when objects are frequently inserted in
and removed from the middle of the sequence?
0 1 0
11. double input = 314159.26; MCQ b = nf.parse( b = nf.format( b = nf.equals( b = 0 1
12. NumberFormat nf = input ); input ); input ); nf.parseObjec
NumberFormat.getInstance(Locale.ITALIAN); t( input );
13. String b;
14. //insert code here
System.out.println("the prize.");
1 0
public class Test { MCQ 123 3 2 23 0 0
public static void main(String [] args) {
int x = 5;
boolean b1 = true;
boolean b2 = false;
int i = iOb.intValue();
1 0
class Trial{ MCQ One Two One Catch One Catch One Two 0 0
public static void main(String[] args){ Catch Finally Finally Catch
try{
System.out.println("One");
int y = 2 / 0;
System.out.println("Two");
}
catch(RuntimeException ex){
System.out.println("Catch");
}
finally{
System.out.println("Finally");
}
}} 1 0
State True or False: MCQ True False 1 0
The main() method of a program can declare
that it throws checked exception.
Given: MCQ Compilation finally finally null 0 1
static void test() { fails. exception
try {
String x = null;
System.out.print(x.toString() + " ");
}
finally { System.out.print("finally "); }
}
public static void main(String[] args) {
try { test(); }
catch (Exception ex) {
System.out.print("exception "); }
}
What is the result? 0 0
Which statement is true? MCQ The notifyAll() To call The notify() The notify() 1 0
method must sleep(), a method is method
be called from thread must defined in causes a
a own the lock class thread to
synchronized on the object java.lang.Threimmediately
context ad release its
locks. 0 0
Which of the following is a checked exception? MCQ Arithmetic IOException NullPointerEx ArrayIndexOut 0 1
Exception ception OfBoundsExc
eption 0 0
Given: MCQ true Not true An exception none 1 0
public void testIfA() { is thrown at
if (testIfB("True")) { runtime.
System.out.println("True");
} else {
System.out.println("Not true");
}
}
public Boolean testIfB(String str) {
return Boolean.valueOf(str);
}
What is the result when method testIfA is
invoked? 0 0
Given the following program,which statements MCQ If run with no If run with no The program If run with one 0 1
is true? arguments,the arguments,the will throw an arguments,the
Public class Exception { program will program will ArrayIndexOut program will
public static void main(String[] args) { produce no produce "The OfBoundsExc simply print
try { output end" eption the given
if(args.length == 0) return; argument
System.out.println(args[0]);
}finally {
System.out.println("The end");
}}} 0 0
Consider the following code and choose the MCQ none of the runtime error does not compiles 0 1
correct option: listed options compile successfully
int array[] = new int[10];
array[-1] = 0; 0 0
class PropagateException{ MCQ Arithmetic Runtime Arithmetic compilation 0 0
public static void main(String[] args){ Exception Exception Exception error
try{ Runtime
method(); Exception
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;
}}
consider the code above & select the proper
output from the options. 1 0
Which statement is true? MCQ A static If a class has Variables can When a 0 1
method synchronized be protected thread sleeps,
cannot be code, multiple from it releases its
synchronized. threads can concurrent locks
still access access
the problems by
nonsynchroniz marking them
ed code. with the
synchronized
keyword. 0 0
What is wrong with the following code? MCQ Since the A try block An empty A catch block A finally block 0 0
method foo() cannot be catch block is cannot follow must always
Class MyException extends Exception{} does not catch followed by not allowed a finally block follow one or
public class Test{ the exception both a catch more catch
public void foo() { generated by and a finally blocks
try { the method block
bar(); baz(),it must
} finally { declare the
baz(); RuntimeExce
} catch(MyException e) {} ption in a
} throws clause
public void bar() throws MyException {
throw new MyException();
}
public void baz() throws RuntimeException {
throw new RuntimeException();
}
} 0 1 0
The exceptions for which the compiler doesn’t MCQ Checked Unchecked Exception all of these 0 1
enforce the handle or declare rule exceptions exceptions 0 0
Consider the following code and choose the MCQ caught exit exit Compilation exit 0 1
correct option: RuntimeExce fails
class Test{ ption thrown
static void display(){ at run time
throw new RuntimeException();
} public static void main(String args[]){
try{display();
}catch(Exception e){ throw new
NullPointerException();}
finally{try{ display();
}catch(NullPointerException e){
System.out.println("caught");}
finally{ System.out.println("exit");}}}} 0 0
class X implements Runnable MCQ Thread t = Thread t = X run = new Thread t = 0 0
{ new Thread(); new X(); Thread t = new
public static void main(String args[]) x.run(); Thread(X); new Thread(X);
{ Thread(run); t.start();
/* Missing code? */ t.start();
}
public void run() {}
}
Which of the following line of code is suitable to
start a thread ? 1 0
Which two can be used to create a new MCA Implement Extend Implement Extend Implement 0.5 0.5
Thread? java.lang.Run java.lang.Thre java.lang.Thre java.lang.Run java.lang.Thre
nable and ad and ad and nable and ad and
implement the override the implement the override the implement the
run() method. run() method. start() start() run() method.
method. method. 0 0 0
Which four can be thrown using the throw MCQ 1, 4, 5 and 6 1, 2, 3 and 4 2, 4, 5 and 6 2, 3, 4 and 5 1 0
statement?
1.Error
2.Event
3.Object
4.Throwable
5.Exception
6.RuntimeException 0 0
Which of the following statements regarding MCA static methods static methods static methods static methods 0 0.5
static methods are correct? (2 answers) are difficult to can be called are always do not have
maintain, using an public, direct access
because you object because they to non-static
can not reference to are defined at methods
change their an object of class-level. which are
implementatio the class in defined inside
n. which this the same
method is class.
defined.
0 0.5
In the given code snippet MCA ClassCastExc NumberForm IllegalStateEx IllegalArgume 0 0.5
try { int a = Integer.parseInt("one"); } eption atException ception ntException
what is used to create an appropriate catch
block? (Choose all that apply.)
A. ClassCastException
B. IllegalStateException
C. NumberFormatException
D. IllegalArgumentException 0 0.5
Which of the following methods are static? MCA sleep() yield() join() start() 0.5 0.5 0 0
class Trial{ MCQ Try Block Try Block Finally Block Finally Block 1 0
public static void main(String[] args){ Finally Block Try Block
try{
System.out.println("Try Block");
}
finally{
System.out.println("Finally Block");
}
}} 0 0
class Animal { public String noise() { return MCQ bark meow Compilation An exception peep 0 0
"peep"; } } fails is thrown at
class Dog extends Animal { runtime.
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());
}}
consider the code above & select the proper
output from the options. 0 1 0
Consider the following code and choose the MCQ caught exit exit Compilation Compiles but 0 0
correct option: fails exception at
class Test{ runtime
static void display(){
throw new RuntimeException();
} public static void main(String args[]){
try{ display(); }catch(Exception e){
throw new NullPointerException();}
finally{try{ display();
}catch(NullPointerException e){
System.out.println("caught");}
System.out.println("exit");}}} 0 1
Consider the following code and choose the MCQ test end test runtime test exception test exception 0 0
correct option: end runtime end end
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) {
try { test(); } catch (RuntimeException ex) {
System.out.print("runtime "); }
System.out.print("end"); } } 0 1
class Test{ MCQ Exception RuntimeExce Exception does not 0 0
public static void main(String[] args){ occurred ption occurred compile
try{ RuntimeExce
Integer.parseInt("1.0"); ption
}
catch(Exception e){
System.out.println("Exception occurred");
}
catch(RuntimeException ex){
System.out.println("RuntimeException");
}
}}
consider the code above & select the proper
output from the options. 0 1
Which of the following statements are true? MCA Deadlock will The wait() A thread will The notify() Both wait() 0 0.33
(Choose TWO) not occur if method is resume method is and notify()
wait()/notify() overloaded to execution as overloaded to must be called
is used accept a soon as its accept a from a
duration sleep duration duration synchronized
expires. context.
0.33 0 0.33
class s implements Runnable MCQ prints 12 12 DeadLock Cannot Compilation 1 0
{ 12 12 determine Error
int x, y; output.
public void run()
{
for(int i = 0; i < 1000; i++)
synchronized(this)
{
x = 12;
y = 12;
}
System.out.print(x + " " + y + " ");
}
public static void main(String args[])
{
s run = new s();
Thread t1 = new Thread(run);
Thread t2 = new Thread(run);
t1.start();
t2.start();
}
} What is the output? 0 0
Which can appropriately be thrown by a MCQ ClassCastExc NullPointerEx NoClassDefF NumberForm 0 0
programmer using Java SE technology to eption ception oundError atException
create
a desktop application? 0 1
What is the keyword to use when the access of MCQ volatile synchronized final private 0 1
a method has to be restricted to only one
thread at a time 0 0
What will be the output of the program? MCQ hello throwit Compilation hello throwit hello throwit 0 0
caught fails RuntimeExce caught finally
public class RTExcept ption caught after
{ after
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 ");
}
System.out.println("after ");
}
} 0 1
Consider the code below & select the correct MCQ 5 Compilation Compiles but 0 0
ouput from the options: error error at run
public class Test{ time
Integer i;
int x;
Test(int y){
x=i+y;
System.out.println(x);
}
public static void main(String[] args) {
new Test(new Integer(5));
}} 1 0
Consider the following code and choose the MCQ exit Compiles and Compilation Compiles but 0 0
correct option: no output fails exception at
class Test{ runtime
static void display(){
throw new RuntimeException();
}
public static void main(String args[]){
try{display();
}catch(Exception e){ }
catch(RuntimeException re){}
finally{System.out.println("exit");}}} 1 0
A) Checked Exception must be explicity caught MCQ Only A is Only B is Bothe A and B Both A and B 0 0
or propagated to the calling method TRUE TRUE is TRUE is FALSE
B) If runtime system can not find an
appropriate method to handle the exception,
then the runtime system terminates and uses
the default exception handler. 1 0
public class MyProgram MCQ The program The program The program The program 0 0
{ will not will print Hello will print Hello will print Hello
public static void throwit() compile. world, then world, then world, then
{ will print that a will print that a will print
throw new RuntimeException(); RuntimeExce RuntimeExce Finally
} ption has ption has executing,
public static void main(String args[]) occurred, then occurred, and then will print
{ will print Done then will print that a
try with try block, Finally RuntimeExce
{ and then will executing. ption has
System.out.println("Hello world "); print Finally occurred.
throwit(); executing.
System.out.println("Done with try block
");
}
finally
{
System.out.println("Finally executing ");
}
}
}
which answer most closely indicates the
behavior of the program?
0 1
If a method is capable of causing an exception MCQ true false 1 0
that it does not handle, it must specify this
behavior using throws so that callers of the
method can guard themselves against such
Exception
class Trial{ MCQ Java is We cannot We cannot Nothing is 0 0
public static void main(String[] args){ portable have a try have a try diaplayed
try{ block without block block
System.out.println("Java is portable"); a catch block without a
}}} catch / finally
block 1 0
public static void parse(String str) { MCQ Compilation A A 0 1
try { fails ParseExceptio NumberForm
float f = Float.parseFloat(str); n is thrown by atException is
} catch (NumberFormatException nfe) { the parse thrown by the
f = 0; method at parse method
} finally { runtime. at runtime.
System.out.println(f);
}
}
public static void main(String[] args) {
parse("invalid");
} 0 0
Which digit,and in what order,will be printed MCQ The program The program The program The program The program 0 0
when the following program is run? will only print will only print will only print will only print will only print
5 1 and 4 in 1,2 and 4 in 1 ,4 and 5 in 1,2,4 and 5 in
Public class MyClass { order order order order
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");
}
System.out.println("5");
}
} 0 1 0
Given: MCQ Synchronizing An exception Compilation Declaring the 0 0
public class TestSeven extends Thread { the run() is thrown at fails. doThings()
private static int x; method would runtime. method as
public synchronized void doThings() { make the static would
int current = x; class thread- make the
current++; safe. class thread-
x = current; safe.
}
public void run() {
doThings();
}
}
Which statement is true? 0 1
Which of the following statements is/are true? MCQ Both Statement 2 is Both Statement 1 is 0 0
Statement 1: Writing finally block is optional. Statement 1 & TRUE but Statement 1 & TRUE but
Statement 2: When no exception occurs then Statement 2 Statement 1 is Statement 2 Statement 2 is
complete try block and finally block will execute are FALSE. FALSE. are TRUE. FALSE.
but no catch block will execute.
1 0
Given: MCQ X run = new Thread t = Thread t = Thread t = 1 0
class X implements Runnable X(); Thread t = new new Thread(); new
{ new Thread(X); x.run(); Thread(X);
public static void main(String args[]) Thread(run); t.start();
{ t.start();
/* Some code */
}
public void run() {}
}
Which of the following line of code is suitable to
start a thread ? 0 0
Given: MCQ X, followed by No output, X, followed by none 1 0
class X { public void foo() { System.out.print("X an Exception. and an an Exception,
"); } } Exception is followed by B.
thrown.
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();
}
}
What is the result? 0 0
Which three of the following are methods of the MCQ 1, 2, 4 2, 4, 5 1, 2, 6 2, 3, 4 0 0
Object class?
1.notify();
2.notifyAll();
3.isInterrupted();
4.synchronized();
5.interrupt();
6.wait(long msecs);
7.sleep(long msecs);
8.yield(); 1 0
public class RTExcept MCQ hello throwit hello throwit hello throwit Compilation 1 0
{ caught finally caught RuntimeExce fails
public static void throwit () after ption caught
{ after
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 ");
}
System.out.println("after ");
}
} 0 0
What will happen when you attempt to compile MCQ A compile A run time Clean compile Clean compile 0 0
and run the following code? time error error and at run but no output
public class Bground extends Thread{ indicating that indicating that time the at runtime
public static void main(String argv[]){ no run method no run method values 0 to 9
Bground b = new Bground(); is defined for is defined for are printed out
b.run(); the Thread the Thread
} class class
public void start(){
for (int i = 0; i <10; i++){
System.out.println("Value of i = "
+ i);
}
}
} 0 1
Given two programs: MCA 567 5 followed by Compilation Compilation Compilation 0 0
1. package pkgA; an exception fails with an fails with an fails with an
2. public class Abc { error on line 7 error on line 8 error on line 9
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. }
12. }
What is the result when the second program is
run? (Choose all that apply) 0 0.5 0.5
What will the output of following code? MCQ finished Exception compilation ArithmeticExc 0 0
fails eption
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("finished");
1 0
Given: MCQ Exception A,B,Exception Compilation Compilation 0 0
11. class A { fails because fails because
12. public void process() { of an error in of an error in
System.out.print("A,"); } line 20. line 14.
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) {
System.out.println("Exception"); }
22. }
What is the result?
0 1
Consider the following code and choose the MCQ reads data Compilation reads data Compiles but 0 1
correct option: from file error from file error at
public class Test { named jlist.lst named jlist.lst runtime
public static void main(String[] args) { in byte form in byte form
File file=new File("D:/jlist.lst"); and display it and display
byte buffer[]=new byte[(int)file.length()+1]; on console. garbage value
FileInputStream fis=new FileInputStream(file);
fis.read(buffer);
System.out.println(buffer);
}
}
0 0
Consider the following code and choose the MCQ reads data Compilation reads data Compiles but 1 0
correct option: from file one error from file error at
public class Test { byte at a time named jlist.lst runtime
public static void main(String[] args) throws and display it in byte form
IOException { on the and display
File file=new File("D:/jlist.lst"); console. garbage value
byte buffer[]=new byte[(int)file.length()+1];
FileInputStream fis=new FileInputStream(file);
int ch=0;
while((ch=fis.read())!=-1){
System.out.print((char)ch); } }}
0 0
import java.io.EOFException; MCQ The program The program The program The program 0 0
import java.io.FileInputStream; will not will compile will compile will compile,
import java.io.FileNotFoundException; compile and print and print print H|e|l|l|o|,
import java.io.IOException; because a H|e|l|l|o|Input H|e|l|l|o|End of and then
import java.io.InputStreamReader; certain error. stream. terminate
public class MoreEndings { unchecked normally.
public static void main(String[] args) { exception is
try { not caught.
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");
}
}
}
Assume that the file "seq.txt" exists in the
current directory, has the required
access permissions, and contains the string
"Hello".
Which statement about the program is true? 0 1
Consider the following code and choose the MCQ I am a Person I am a Student I am a Person I am a Student 0 1
correct output: I am a Student I am a Person
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();
}
} 0 0
Consider the following code and choose the MCQ Skip the first Compilation Compiles and Compiles but 1 0
correct option: seven error runs without error at
public class Test{ characters output runtime
public static void main(String[] args) throws and then
IOException { starts reading
File file = new File("d:/temp.txt"); file and
FileReader reader=new FileReader(file); display it on
reader.skip(7); int ch; console
while((ch=reader.read())!=-1){
System.out.print((char)ch); } }} 0 0
Consider the following code and choose the MCQ reads data Compilation reads data Compiles but 1 0
correct option: from file error from file error at
public class Test { named jlist.lst named jlist.lst runtime
public static void main(String[] args) throws in byte form in byte form
IOException { and display it and display
File file=new File("D:/jlist.lst"); on console. garbage value
byte buffer[]=new byte[(int)file.length()+1];
FileInputStream fis=new FileInputStream(file);
fis.read(buffer);
System.out.println(new String(buffer)); }}
0 0
Which of these are two legal ways of accessing MCQ A,D B,C C,D A,B 0 0
a File named "file.tst" for reading. Select the
correct option:
A)FileReader fr = new FileReader("file.tst");
B)FileInputStream fr = new
FileInputStream("file.tst");
C)InputStreamReader isr = new
InputStreamReader(fr, "UTF8");
D)FileReader fr = new FileReader("file.tst",
"UTF8"); 0 1
Consider the following code and choose the MCQ the state of Compilation Compiles but the state of 0 0
correct option: the object s1 error error at run the object s1
class std{ will be store to time will not be
int call; std(int c){call=c;} file std.txt store to the
int getCall(){return call;} file.
}
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);
std s1=new std(10);
oos.writeObject(s1);
oos.close();
}} 1 0
Consider the following code and choose the MCQ reads data Compilation reads data Compiles but 0 0
correct option: from file one error from file error at
public class Test { byte at a time named jlist.lst runtime
public static void main(String[] args) throws and display it in byte form
IOException { on the and ascii
File file=new File("D:/jlist.lst"); console. value
byte buffer[]=new byte[(int)file.length()+1];
FileInputStream fis=new FileInputStream(file);
int ch=0;
while((ch=fis.read())!=-1){
System.out.print(ch); } }}
1 0
What happens when the constructor for MCQ throws a throws a throws a returns null 0 1
FileInputStream fails to open a file for reading? DataFormatEx FileNotFound ArrayIndexOut
ception Exception OfBoundsExc
eption 0 0
import java.io.*; MCQ Compilation An exception An instance of A instance of 1 0
public class MyClass implements Serializable { fails is thrown at MyClass is MyClass and
runtime serialized an instance of
private Tree tree = new Tree(); Tree are both
serialized
public static void main(String [] args) {
MyClass mc= new MyClass();
try {
FileOutputStream fs = new
FileOutputStream(”MyClass.ser”);
ObjectOutputStream os = new
ObjectOutputStream(fs);
os.writeObject(mc); os.close();
} catch (Exception ex) { ex.printStackTrace(); }
}}
0 0
What is the DataOutputStream method that MCQ writeBytes() writeFloat() write() writeDouble() 0 0
writes double precision floating point values to
a stream? 0 1
Which of the following opens the file MCQ FileOutputStre FileOutputStre DataOutputStr FileOutputStre 0 1
"myData.stuff" for output first deleting any file am fos = new am fos = new eam dos = am fos = new
with that name? FileOutputStre FileOutputStre new FileOutputStre
am( am( DataOutputStr am( new
"myData.stuff" "myData.stuff" eam( BufferedOutp
, true ) ) "myData.stuff" utStream(
) "myData.stuff"
))
0 0
A file is readable but not writable on the file MCQ A The boolean The boolean
The file is none of the 0 1
system of the host platform. What will SecurityExcep value false is value true is
modified from listed options
be the result of calling the method canWrite() tion is thrown returned returned
being
on a File object representing this file? unwritable to
being
writable. 0 0 0
Consider the following code and choose the MCQ The file The file The file The file Compilation 0 0
correct option: system has a system has a system has a system has a error
public class Test{ new empty new empty directory directory
public static void main(String[] args) { directory directory named dir, named
File dir = new File("dir"); named dir named containing a newDir,
dir.mkdir(); newDir file f1.txt containing a
File f1 = new File(dir, "f1.txt"); try { file f1.txt
f1.createNewFile(); } catch (IOException e) { ;
}
File newDir = new File("newDir");
dir.renameTo(newDir);} } 0 1 0
Consider the following code and choose the MCQ writes data to Compilation writes data to Compiles but 1 0
correct option: file in byte error the file in error at
public class Test { form. character runtime
public static void main(String[] args) throws form.
IOException {
String data="Confidential info";
byte buffer[]=data.getBytes();
FileOutputStream fos=new
FileOutputStream("d:/temp");
for(byte d : buffer){
fos.write(d); } }} 0 0
Consider the following code and choose the MCQ creates Compilation Compiles but Compiles and 0 0
correct option: directories error error at run executes but
public class Test { names prj and time directories are
public static void main(String[] args) { lib in d: drive not created
File file=new File("d:/prj,d:/lib");
file.mkdirs();}} 0 1
Consider the following code and choose the MCQ Transfer Compilation Compiles and Compiles but 0 0
correct option: content of file error runs but error at
public class Test { data to the content not runtime
public static void main(String[] args) throws temp.txt transferred to
IOException { the temp.txt
File file=new File("d:/data");
byte buffer[]=new byte[(int)file.length()+1];
FileInputStream fis=new FileInputStream(file);
fis.read(buffer);
FileWriter fw=new FileWriter("d:/temp.txt");
fw.write(new String(buffer));}}
1 0
Consider the following code and choose the MCQ the state of Compilation Compiles but the state of 1 0
correct option: the object s1 error error at run the object s1
class std implements Serializable{ will be store to time will not be
int call; std(int c){call=c;} file std.txt store to the
int getCall(){return call;} file.
}
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);
std s1=new std(10);
oos.writeObject(s1);
oos.close();
}} 0 0
Given : MCQ ab abcd ab cd abcd Compilation 0 0
import java.io.*; Error
public class ReadingFor {
public static void main(String[] args) {
String s;
try {
FileReader fr = new FileReader("myfile.txt");
BufferedReader br = new BufferedReader(fr);
while((s = br.readLine()) != null)
System.out.println(s);
br.flush();
} catch (IOException e) {
System.out.println("io error"); }
}
}
And given that myfile.txt contains the following
two lines of data:
ab
cd
What is the result? 0 0 1
Consider the following code and choose the MCQ creates Compilation Compiles but Compiles and 1 0
correct option: directory error error at run executes but
public class Test { d:/prj/lib time directory is not
public static void main(String[] args) { created
File file=new File("d:/prj/lib");
file.mkdirs();}} 0 0
import java.io.*; MCQ s.writeInt(x); s.serialize(x); s.defaultWrite s.writeObject( 0 0
public class MyClass implements Serializable { Object(); x);
private int a;
public int getA() { return a; }
publicMyClass(int a){this.a=a; }
private void writeObject( ObjectOutputStream
s)
throws IOException {
// insert code here
}
}
while (rs.next()) {
String name = rs.getString("name");
System.out.println(name);
}
rs.close();
// somecode
} What should be imported related to
ResultSet? 0 0
Consider the following code & select the MCQ will show first Compilation Compiles but Compiles but 0 0
correct option for output. employee error error at run no output
String sql ="select empno,ename from emp"; record time
PreparedStatement
pst=cn.prepareStatement(sql);
System.out.println(pst.toString());
ResultSet rs=pst.executeQuery();
System.out.println(rs.getString(1)+ "
"+rs.getString(2));
1 0
What is the default type of ResultSet in JDBC MCQ Read Only, Updatable, Read only, Updatable, 1 0
applications? Forward Only Forward only Scroll Scroll
Sensitive sensitive 0 0
Consider the code below & select the correct MCQ will show all Compilation Compiles but Compiles but 0 0
ouput from the options: row of first error error at run run without
column time output
String sql ="select * from ?";
String table=" txyz ";
PreparedStatement
pst=cn.prepareStatement(sql);
pst.setString(1,table );
ResultSet rs=pst.executeQuery();
while(rs.next()){
System.out.println(rs.getString(1)); } 1 0
Cosider the following code & select the correct MCQ will show only Compilation will show city Compiles but 0 0
output. name error error at run
String sql ="select rollno, name from student"; time
PreparedStatement
pst=cn.prepareStatement(sql);
System.out.println(pst.toString());
ResultSet rs=pst.executeQuery();
while(rs.next()){
System.out.println(rs.getString(3)); }
0 1
Given : MCQ java.sql.Driver java.sql.Driver java.sql.Driver java.sql.DataS 0 0
public class MoreEndings { java.sql.Driver ource
public static void main(String[] args) throws Manager
Exception {
Class driverClass =
Class.forName("sun.jdbc.odbc.JdbcOdbcDrive
r");
DriverManager.registerDriver((Driver)
driverClass.newInstance());
// Some code
} Inorder to compile & execute this code, what
should we import? 1 0
Which of the following methods finds the MCQ Database.get Connection.ge DatabaseMet ResultSetMet 0 0
maximum number of connections that a MaxConnectio tMaxConnecti aData.getMax aData.getMax
specific driver can obtain? ns ons Connections Connections 1 0
Which of the following method can be used to MCQ executeAll() executeAllSQ execute() executeQuery executeUpdat 0 0
execute to execute all type of queries i.e. either L() () e()
Selection or Updation SQL Queries? 1 0 0
It is possible to insert/update record in a table MCQ true false 1 0
by using ResultSet. State TRUE/FALSE
Which of the following methods are needed for MCQ registerDriver( Class.forNam registerDriver( getConnection 0 0
loading a database driver in JDBC? ) method e() ) method and
Class.forNam
e() 1 0
Carefully read the question and answer MCQ specifier Inheritance Implementatio Access Class 0 0
accordingly. n specifier
________ determines which member of a class
can be used by other classes. 0 1 0
Carefully read the question and answer MCQ protected final,interface public,friend final,protected private,abstra 0 1
accordingly. ,interface ct
A class can be declared as _______ if you do
not want the class to be subclassed. Using
the __________keyword we can abstract a
class from its implementation
0 0 0
Carefully read the question and answer MCQ super class display display super class 0 1
accordingly. method method method method
What will be the output for following code? display display display display
class Super method 20 20 method 10 10 method 20 20 method 10 10
{
int num=20;
public void display()
{
System.out.println("super class method");
}
}
public class ThisUse extends Super
{
int num;
public ThisUse(int num)
{
this.num=num;
}
public void display()
{
System.out.println("display method");
}
public void Show()
{
this.display();
display();
System.out.println(this.num);
System.out.println(num);
}
public static void main(String[]args)
{
ThisUse o=new ThisUse(10); 0 0
o.Show();read the question and answer
Carefully MCQ 10 11 Compilation None of the 0 0
accordingly. error listed options
What will be the output for following code?
public class Variables
{
public static void main(String[]args)
{
public int i=10;
System.out.println(i++);
}
} 1 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
The constructor of a class must not have a
return type.
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
When one method is overridden in sub class
the access specifier of the method in sub class
should be equal as method in super class.
State True or False.
Carefully read the question and answer MCQ Class Public Constructor Destructor Variable 0 0
accordingly.
Which of the following method is used to
initialize the instance variable of a class. 1 0 0
Carefully read the question and answer MCQ protected or protected or None of the private 0 1
accordingly. default public listed options
If display method in super class has a
protected specifier then what should be the
specifier for the overriding display method in
sub class? 0 0
Carefully read the question and answer MCQ super class super class sub class Compilation 1 0
accordingly. show method show method show method Error
What will be the output for following code? sub class super class
class Super show method show method
{
static void show()
{
System.out.println("super class show
method");
}
static class StaticMethods
{
void show()
{
System.out.println("sub class show method");
}
}
public static void main(String[]args)
{
Super.show();
new Super.StaticMethods().show();
}
}
0 0
Carefully read the question and answer MCQ I II & IV III I & III 1 0
accordingly.
Which of the following statements are true
about Method Overriding?
I: Signature must be same including return
type
II: If the super class method is throwing the
exception then overriding method should throw
the same Exception
III: Overriding can be done in same class
IV: Overriding should be done in two different
classes with no relation between the classes 0 0
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
A field with default access specifier can be
accessed out side the package.
State True or False.
Carefully read the question and answer MCQ If one class is A class can All members Protected is 1 0
accordingly. having be declared of abstract default access
Which of the following are true about protected protected as protected. class are by modifier of a
access specifier? method then default child class
the method is protected
available for
subclass
which is
present in
another
package 0 0
Carefully read the question and answer MCQ super class super class Compilation None of the 1 0
accordingly. exe method exe method error listed options
What will be the output of following code? sub class super class
class Super2 display display
{ method method
public void display()
{
System.out.println("super class display
method");
}
public void exe()
{
System.out.println("super class exe method");
display();
}
}
public class InheritMethod extends Super2
{
public void display()
{
o.exe();
}
0 0
}
Carefully read the question and answer MCQ Constructors Constructors Constructor is Constructors 1 0
accordingly. can be can be a special type should be
Which of the following are true about overloaded overridden. of method called
constructors? which may explicitly like
have return methods
type. 0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Constructor of an class is executed each time
when an object of that class is created
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State whether TRUE or FALSE.
The below code will compile & provide
desired output:
package p1;
class Parent {
private int doWork(){
System.out.println("Do Work - Parent");
return 0;
}
}
class Child extends Parent {
public void doWork(){
System.out.println("Do Work - Child");
}
}
class Test{
public static void main(String[] args) {
new Child().doWork();
}
}
Carefully read the question and answer MCQ 1&2 1&2&3 2&3 1&2&4 2&4 0 0
accordingly.
public interface Status
{
/* insert code here */ int MY_VALUE = 10;
}
Which are valid on commented line?
1.final
2.static
3.native
4.public 0 1 0
Carefully read the question and answer MCQ Child Parent Parent Child Parent Child 0 0
accordingly.
What is the outputof below code:
package p1;
class Parent {
public static void doWork() {
System.out.println("Parent");
}
}
class Child extends Parent {
public static void doWork() {
System.out.println("Child");
}
}
class Test {
public static void main(String[] args) {
Child.doWork();
}
} 1 0
Carefully read the question and answer MCQ 1&2 1&3 2&3 3&4 2&4 0 0
accordingly.
abstract public class Employee
{
protected abstract double getSalesAmount();
public double getCommision() {
return getSalesAmount() * 0.15;
}
}
class Sales extends Employee
{
// insert method here
}
Which two methods, inserted independently,
correctly complete the Sales
class?
1.double getSalesAmount() { return 1230.45; }
2. public double getSalesAmount() { return
1230.45; }
3.private double getSalesAmount() { return
1230.45; }
4.protected double getSalesAmount() { return
1230.45; }
0 0 1
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State whether TRUE or FALSE.
Object class provides a method named
getClass() which returns runtime class of an
object.
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
State whether TRUE or FALSE.
A concrete class can extend more than one
super class whether that super class is either
concrete or abstract class
Carefully read the question and answer MCQ final protected static abstract 1 0
accordingly.
Which of the following keywords ensures that a
method cannot be overridden? 0 0
Carefully read the question and answer MCQ Class cannot Runtime WD 500 Compile 0 0
accordingly. be defined Error. Error.
public class Client1 inside another
{ class
public static void main(String [] args)
{
PenDrive p;
PenDrive.Vendor v1=new
PenDrive.Vendor("WD",500);
System.out.println(v1.getName());
System.out.println(v1.getPrice());
}
}
class PenDrive
{
static class Vendor
{
String name;
int price;
public String getName(){ return name;}
public int getPrice(){ return price;}
Carefully read the question and answer MCA try catch finally access exception 0 0
accordingly.
Find the keyword which is not used to
implement exception 0 0.5 0.5
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
The ++ operator postfix and prefix has the
same effect
Carefully read the question and answer MCQ 102 34 4 Compilation 0 1
accordingly. error
What will be the output for following code?
public class VariableDec
{
public static void main(String[]args)
{
int x = 1;
if(x>0 )
x = 3;
switch(x)
{
case 1: System.out.println(1);
case 0: System.out.println(0);
case 2: System.out.println(2);
break;
case 3: System.out.println(3);
default: System.out.println(4);
break;
}
}
} 0 0
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
Garbage collection guarantee that a program
will not run out of memory. State True or False.
Carefully read the question and answer MCQ 12,12,-1 13,12,0 13,13,0 12,13,-1 0 1
accordingly.
What will be the output for following code?
public class Operators
{
public static void main(String[]args)
{
int i=12;
int j=13;
int k=++i-j--;
System.out.println(i);
System.out.println(j);
System.out.println(k);
}
} 0 0
Carefully read the question and answer MCQ extends implements throwed Integer Boolean 0 0
accordingly.
Which of the following is not the Java
keyword? 1 0 0
Carefully read the question and answer MCQ class new print main Object 0 1
accordingly.
_____________ Operator is used to create an
object. 0 0 0
Carefully read the question and answer MCQ III->I->II->IV. I->III->II->IV I->III->IV->II I->II->III->IV 1 0
accordingly.
What is the correct structure of a java
program?
I: import statement
II: class declaration
III: package statement
IV: method,variable declarations 0 0
Carefully read the question and answer MCQ An exception The code The code Compilation 1 0
accordingly. is thrown at executes executes fails.
public class Threads runtime. normally and normally, but
{ prints "Run". nothing is
public static void main (String[] args) printed.
{
new Threads().go();
}
public void go()
{
Runnable r = new Runnable()
{
public void run()
{
System.out.print("Run");
}
};
Carefully read the question and answer MCQ boolean void Object String 0 0
accordingly.
What is the return type of next() in Iterator? 1 0
Carefully read the question and answer MCQ Creates a Creates a Creates a Creates a 0 0
accordingly. Date object Date object Date object Date object
Consider the following partial code: with 0 as with '01-01- with current with current
java.util.Date date = new java.util.Date(); default value 1970 12:00:00 date and time date alone as
Which of the following statement is true AM' as default as default default value
regarding the above partial code? value value
1 0
Carefully read the question and answer MCA The Iterator The The The 0.33 0
accordingly. interface ListIterator ListIterator ListIterator
Which of the following are true statements? declares only interface interface interface
three extends both provides the provides
methods: the List and ability to forward and
hasNext, next Iterator determine its backward
and remove. interfaces position in the iteration
List. capabilities. 0.33 0.33
Carefully read the question and answer MCQ int String Object set1 0 0
accordingly.
What is the data type of m in the following
code?
import java.util.*;
public class set1
{
public static void main(String [] args)
{
Set s=new HashSet();
s.add(20);
s.add("abc");
for( _____ m:s)
System.out.println(m);
}
} 1 0
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
Enumeration is having remove() method.
State True or False.
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
The add method of Set returns false if you try to
add a duplicate element.
Carefully read the question and answer MCA Line 1 has Line 2 has run In Line 4 null Line 4 has 0.5 0
accordingly. compilation time pointer neither error
As per the below code find which statements error exceptions exception will nor
are true. occur as exceptions.
public class Test { String string
public static void main(String[] args) { contains null
Line 1: ArrayList<String> myList=new value
List<String>();
Line 2: String string = new String();
Line 3: myList.add("string");
Line 4: int index = myList.indexOf("string");
System.out.println(index);
}
}
0 0.5
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
State TRUE or FALSE.
line 1: public class Test {
line 2: public static void main(String[] args) {
line 3: Queue queue = new LinkedList();
line 4: queue.add("Hello");
line 5: queue.add("World");
line 6: List list = new ArrayList(queue);
line 7: System.out.println(list); }
line 8: }
Above code will give run time error at line
number 3.
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
The LinkedList class supports two constructors.
Carefully read the question and answer MCA Hash Map Array List Collection Sorted Map 0 0
accordingly.
Which of these are interfaces in the collection
framework 0.5 0.5
Carefully read the question and answer MCA java.utill.Map java.util.Array java.util.Dictio java.util.Hash 0 0
accordingly. List nary Map
Which collection class allows you to associate
its elements with key values 0.5 0.5
Carefully read the question and answer MCA Serializable SortTable SortedSet Comparable 0 0
accordingly.
TreeSet uses which two interfaces to sort the
data 0.5 0.5
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Iterator i= new HashMap().entrySet().iterator();
is this correct declaration
Carefully read the question and answer MCA The elements The elements The elements HashSet 0 0.5
accordingly. in the in the in the allows at most
Which statement are true for the class collection are collection arecollection are one null
HashSet? accessed guaranteed to accessed element
using a be unique using a
unique key. unique key. 0 0.5
Carefully read the question and answer MCA All All All all 0.33 0.33
accordingly. implementatio implementatio implementatio implementatio
which are the Basic features of ns are ns support ns are ns are
implementations of interfaces in Collections unsynchronize having null serializable immutable
Framework in java? d elements. and cloneable and supports
duplicates
data 0.33 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
Map is the super class of Dictionary class?
Carefully read the question and answer MCA for loop list Iterator foreach Iterator 0 0
accordingly.
what is the way to iterate over the elements of
a Map 0.5 0.5
Carefully read the question and answer MCQ Both the Statement A Statement A Both the 0 0
accordingly. Statements A is true and is false and statements A
Consider the following Statements: and B are true Statement B Statement B and B are
Statement A: The Iterator interface declares is false is true false.
only two methods: hasMoreElements and
nextElement.
Statement B: The ListIterator interface extends
both the List and Iterator interfaces.
Which of the following option is correct
regarding above given statements? 0 1
Carefully read the question and answer MCQ A B C D E 0 0
accordingly.
Consider the following list of code:
A) Iterator iterator =
hashMap.keySet().iterator();
B) Iterator iterator = hashMap.iterator();
C) Iterator iterator =
hashMap.keyMap().iterator();
D) Iterator iterator =
hashMap.entrySet().iterator();
E) Iterator iterator =
hashMap.entrySet.iterator();
Assume that hashMap is an instance of
HashMap type collection implementation.
Which of the following option gives the correct
partial code about getting an Iterator to the
HashMap entries? 0 1 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
List<Integer> newList=new
ArrayList<integer>(); will Above statement
create a new object of Array list successfully ?
0 0
Carefully read the question and answer MCQ both strings both strings compilation Strings cannot 0 1
accordingly. are equal are not equal error be compare
What will be the output for following code? using ==
public class CompareStrings{ operator
public static void main(String[]args){
String a=new String("string");
String s=new String("string");
if(a==s)
System.out.println("both strings are equal");
else
System.out.println("both strings are not
equal");
}
} 0 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
State whether TRUE or FALSE.
String class do not provides a method which is
used to compare two strings lexicographically.
Carefully read the question and answer MCQ Statement I & Statement I is Statement I is Statement I & 1 0
accordingly. II are TRUE TRUE & II is FALSE & II is II are FASLE
Choose the correct option. FALSE TRUE
Statement I: StringBuilder offers faster
performance than StringBuffer
Statement II: All the methods available on
StringBuffer are also available on StringBuilder
0 0
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
endsWith() member methods of String class
creates new String object. State True or False
Carefully read the question and answer MCQ Statement I & Statement I is Statement I is Statement I & 0 1
accordingly. II are TRUE TRUE & II is FALSE & II is II are FASLE
Choose the correct option. FALSE TRUE
Statement I: StringBuffer is efficient than “+”
concatenation
Statement II: Using API’s in StringBuffer the
content and length of String can be changed
which intern creates new object. 0 0
Carefully read the question and answer MCQ FALSE TRUE 0 1
accordingly.
State whether TRUE or FALSE.
String s = new String(); is valid statement in
java
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
Consider the following code snippet:
String thought = "Green";
StringBuffer bufferedThought = new
StringBuffer(thought);
String secondThought =
bufferedThought.toString();
System.out.println(thought ==
secondThought);
Which of the following option gives the output
of the above code snippet?
Carefully read the question and answer MCQ Comparing Searching Extracting All of above 0 0
accordingly. strings strings strings
String class contains API used for 0 1
Carefully read the question and answer MCQ Error x = Java x = Rules x = Java 0 0
accordingly. Rules
What is the output of below code:
package p1;
public class Hackathon {
public static void main(String[] args) {
String x = "Java";
x.concat(" Rules!");
System.out.println("x = " + x);
}
} 0 1
Carefully read the question and answer MCQ both strings both strings compilation Strings cannot 0 1
accordingly. are equal are not equal error be compare
What will be the output for following code? using ==
public class CompareStrings{ operator
public static void main(String[]args){
if(" string ".trim()=="string")
System.out.println("both strings are equal");
else
System.out.println("both strings are not
equal");
}
} 0 0
Carefully read the question and answer MCQ 4 5 6 None of the 0 1
accordingly. listed options
What will be the output for following code?
import java.util.*;
public class StringTokens
{
public static void main(String[]args)
{
String s="India is a\n developing country";
StringTokenizer o=new StringTokenizer(s);
System.out.println(o.countTokens());
}
} 0 0
Carefully read the question and answer MCQ x = JAVA x="" x = Java x="JAVA" 0 0
accordingly.
What is the output of below code:
package p1;
public class Hackathon {
public static void main(String[] args) {
String x = "Java";
x.toUpperCase();
System.out.println("x = " + x);
}
} 1 0
Carefully read the question and answer MCQ 1&2 1&2&3 1&3 2 2&3 1 0
accordingly.
What will be the output for following code?
public class Exe3
{
public static void main(String[]args)
{
try
{
int i=10;
int j=i/0;
return;
}catch(Exception e)
{
System.out.println("welcome");
}
System.out.println("error");
}
}
1.welcome
2.error
3.compilation error 0 0 0
Carefully read the question and answer MCQ welcome error compilation None of the 1 0
accordingly. error listed options
What will be the output for following code?
public class Exe3 {
public static void main(String[]args){
try{
int i=10;
int j=i/0;
return;
}catch(Exception e){
try{
System.out.println("welcome");
return;
}catch(Exception e1){
}
System.out.println("error");
}
}
} 0 0
Carefully read the question and answer MCQ IOException compilation Runtime error None of the 0 1
accordingly. error listed options
What will be the output for following code?
class super5{
void Get()throws Exception{
System.out.println("IOException");
}
}
public class Exception2 extends super5{
public static void main(String[]args){
super5 o=new super5();
try{
o.Get();
}catch(IOException e){
}
}
} 0 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
Propagating exceptions across modules is not
possible without throw and throws keyword.
State True or False.
Carefully read the question and answer MCQ 1&2 1&2&3 1&3&4 1&2&4 2&4 0 0
accordingly.
What will be the output of following code?
public class Exception1{
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i/j > 1)
i++;
} catch(ArithmeticException e) {
System.out.println(0);
} catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
} catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}
1.0
2.1
3.3
4.4.
1 0 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
try and throws keywords are used to manually
throw an exception?
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
RuntimeException is the superclass of those
exceptions that can be thrown during the
normal operation of the Java Virtual Machine.
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Error is the sub class of Throwable
Carefully read the question and answer MCQ throws catch ( throws No code is 0 0
accordingly. RuntimeExce Exception e ) Exception necessary.
At Point X in below code, which code is ption
necessary to make the code compile?
public class Test
{
class TestException extends Exception {}
public void runTest() throws TestException {}
public void test() /* Point X */
{
runTest();
}
}
1 0
Carefully read the question and answer MCQ Shows Shows Demands a Demands a 0 0
accordingly. unhandled unhandled finally block at finally block at
Consider the following code: exception type exception type line number 4 line number 5
1 public class FinallyCatch { IOException IOException
2 public static void main(String args[]) { at line number at line number
3 try { 4 5
4 throw new java.io.IOException();
5 }
6 }
7 }
Which of the following is true regarding the
above code? 0 1
Carefully read the question and answer MCA A NoClassDefF NoClassDefF None of the 0.5 0.5
accordingly. ClassNotFoun oundError oundError is a options
Which is/are true among given statements dException is means that subClass of
thrown when the class was ClassNotFoun
the reported found by the dException
class is not ClassLoader
found by the however
ClassLoader when trying to
in the load the class,
CLASSPATH. it ran into an
error reading
the class
definition. 0 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
is it valid to place some code in between try
and catch blocks.
Carefully read the question and answer MCQ Throwable throws throw RuntimeExce 1 0
accordingly. ption
Which is the super class for Exception and
Error? 0 0
Carefully read the question and answer MCA An exception The use of finally block The death of 0.33 0.33
accordingly. arising in the System.exit() will be always the thread
If you put a finally block after a try and its finally block executed in
associated catch blocks, then once execution itself any
enters the try block, the code in that finally circumstances
block will definitely be executed except in some .
circumstances.select the correct circumstance
from given options: 0 0.33
Carefully read the question and answer MCQ 1&2 1&3 2&3 1&4 2&4 1 0
accordingly.
Which of the following are checked
exceptions?
1.ClassNotFoundException
2.InterruptedException
3.NullPointerException
4.ArrayIndexOutOfBoundsException 0 0 0
Carefully read the question and answer MCQ An exception A catch block Both catch All of the 0 0
accordingly. which is not can have block and listed options
Which of the following statement is true handled by a another try finally block
regarding try-catch-finally? catch block block nested can throw
will be inside exceptions
handled by
subsequent
catch blocks 0 1
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
The finally block always executes when the try
block exits.
State True or False.
Carefully read the question and answer MCQ Executing try Executing try Compile Time Runtime 0 0
accordingly. After try Runtime Exception Exception
What will be the output of following code? Executing Exception
try catch
{
System.out.println("Executing try");
}
System.out.println("After try");
catch (Exception ex)
{
System.out.println("Executing catch");
}
1 0
Carefully read the question and answer MCQ 2 3 compilation 0 0
accordingly. error
What will be the output for following code?
public class Exception1{
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i/j > 1)
i++;
} catch(Exception e) {
System.out.println(2);
} catch(ArithmeticException e) {
System.out.println(0);
}
finally {
System.out.println(3);
}
}
} 1
Carefully read the question and answer MCQ hello 0 hello 0 Math hello Math hello string 0 0
accordingly. stopped problem occur problem occur problem occur
What will be the output of the below code? stopped string problem stopped
public class Test { occur problem
public static void main(String[] args) { occurs
int a = 5, b = 0, c = 0; stopped
String s = new String();
try {
System.out.print("hello ");
System.out.print(s.charAt(0));
c = a / b;
} catch (ArithmeticException ae) {
System.out.print(" Math problem occur");
} catch (StringIndexOutOfBoundsException
se) {
System.out.print(" string problem occur");
} catch (Exception e) {
System.out.print(" problem occurs");
} finally {
System.out.print(" stopped");
}
}
} 0 1
Carefully read the question and answer MCQ try finally throw throwable 0 0
accordingly.
Which of these keywords is used to explicitly
throw an exception? 1 0
Carefully read the question and answer MCQ A,C A Compilation None of the 0 1
accordingly. error listed options
What will be the output for following code?
public class Exception1
{
public static void main(String[]args)
{
System.out.println("A");
try
{
System.exit(0);
}catch(Exception e)
{
System.out.println("B");
}
System.out.println("C");
}
}
} 0 0
Carefully read the question and answer MCA IOException Throwable RunTimeExce FileNotFindEx 0.33 0
accordingly. ption ception
which of these are the subclass of Exception
class 0.33 0.33
Carefully read the question and answer MCA try final thrown catch 0.5 0
accordingly.
Which of these keywords are a part of
exception handling? 0 0.5
Carefully read the question and answer MCQ Prints Compiler time Compile time Run time error 1 0
accordingly. Exception error User error Cannot test() method
Consider the following code: defined use does not
class MyException extends Throwable { } exceptions Throwable to throw a
public class TestThrowable { should extend catch the Throwable
public static void main(String args[]) { Exception exception instance
try {
test();
} catch(Throwable ie) {
System.out.println("Exception");
}
}
Carefully read the question and answer MCQ 1&2 1&5 2&3 1&4 2&4 0 0
accordingly.
Select two runtime exceptions.
1.SQLException
2.NullPointerException
3.FileNotFoundException
4.ArrayIndexOutOfBoundsException
5.IOException 0 0 1
Carefully read the question and answer MCA Try block if exception catch block is after switching 0 0
accordingly. always occurs, not mandate from try block
which are true for try block needed a control always only to catch block
catch block switches to finally the control
followed following first followed by try never come
Catch block can be back to try
executed block to
execute rest
of the code
0.5 0.5
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Try can be followed with either catch or finally.
State True or False.
Carefully read the question and answer MCA A checked error and Checked All runtime 0.5 0
accordingly. exception is a checked exceptions exceptions
which are correct for checked exceptions subclass of exceptions are the object are checked
throwable are same. of the exceptions
class Exception
class or any of
its subclasses
except
Runtime
Exception
class.
0.5 0
Carefully read the question and answer MCQ Compile time A A,C Runtime error 1 0
accordingly. error
What will be the output for following code?
import java.io.*;
public class Exception1
{
public static void main(String[]args)
{
System.out.println("A");
try
{
}
catch(IOException t)
{
System.out.println("B");
}
System.out.println("C");
}
} 0 0
Carefully read the question and answer MCQ Both Statement A Statement A Both 1 0
accordingly. Statements A is true and is false and Statements A
Which of the following statement is true and B are true Statement B Statement B and B are
regarding implementing user defined exception is false is true false
mechanisms?
Statement A: It is valid to derive a class from
java.lang.Exception
Statement B: It is valid to derive a class from
java.lang.RuntimeException 0 0
Carefully read the question and answer MCA Class Cast Array Index ClassNotFoun Number 0.33 0.33
accordingly. Exception Out Of dException Format
which are the Unchecked exceptions Bounds Exception
Exception 0 0.33
Carefully read the question and answer MCQ IOException FileNotFound SQLException NullPointerEx 0 0
accordingly. Exception ception
Which of the following exception is not
mandatory to be handled in code? 0 1
Carefully read the question and answer MCQ statement statement statement statement 0 1
accordingly. 1:true 1:false 1:false 1:true
Statement 1:static variables can be serialized statement2:tru statement2:tru statement2:fal statement2:fal
Statement2:transient variables cannot be e e se se
serialized
which of the following is true?
0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State TRUE or FALSE.
getParent() gives the parent directory of the file
and isFile() Tests whether the file denoted by
the given abstract pathname is a normal file.
Carefully read the question and answer MCQ DataInput ObjectInput ObjectFilter FileFilter 0 0
accordingly.
Which of these interface is not a member of
java.io package? 1 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
BufferedWriter constructor CAN ACCEPT
Filewriter Object as a parameter.
State True or False.
Carefully read the question and answer MCA File Writer Reader OutputStream 0 0.33
accordingly.
Which of these class are related to input and
output stream in terms of functioning? 0.33 0.33
Carefully read the question and answer MCQ java/system /java/system system compilation 0 0
accordingly. error
What is the output of this program?
1. import java.io.*;
2. class files {
3. public static void main(String args[]) {
4. File obj = new File("/java/system");
5. System.out.print(obj.getName());
6. }
7. }
1 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
isFile() returns true if called on a file or when
called on a directory
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Serialization is representing object in a
sequence of bytes. State True or False.
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
An ObjectInputStream deserializes objects
previously written using an
ObjectOutputStream.
State True or False.
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
InputStream is the class used for stream of
characters.
State True or False.
Carefully read the question and answer MCA BufferedOutp setting up it has flush() As bytes from 0.33 0.33
accordingly. utStream BufferedOutp method the stream are
select the correct statements about class is a utStreaman , read or
BufferedOutputStream class member of an application skipped, the
Java.io can write internal buffer
package bytes to the is refilled as
underlying necessary
output stream from the
without contained
necessarily input stream,
causing a call many bytes at
to the a time.
underlying
system for
each byte
written. 0.33 0
Carefully read the question and answer MCQ Runnable Serializable Externalizable None of the 0 1
accordingly. listed options
Which of the following is a marker interface
used for object serialization? 0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
DataInputStream is not necessarily safe for
multithreaded access.
Carefully read the question and answer MCA ObjectInput StringReader File String 0 0.5
accordingly.
Which of these class are the member class of
java.io package? 0.5 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
InputStreamReader is sub class of
FilterReader.
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
The InputStream.close() method closes this
stream and releases all system resources
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Serialization is JVM independent.State True or
False.
Carefully read the question and answer MCQ 1&2 1&2&3 1&3&4 1&2&4 2&4 0 0
accordingly.
Which of the following are abstract classes?
1.Reader
2.InputStreamReader
3.InputStream
4.OutputStream 1 0 0
Carefully read the question and answer MCQ 10 11 12 None of the 0 1
accordingly. listed options
What is the value of variable "I" after execution
of following code?
public class Evaluate
{
public static void main(String[]args)
{
int i=10;
if(((i++)>12)&&(++i<15))
System.out.println(i);
else
System.out.println(i);
}
} 0 0
Carefully read the question and answer MCQ switch continue break label branch 1 0
accordingly.
_____________ is a multi way branch
statement 0 0 0
Carefully read the question and answer MCQ 100 Compilation code will runtime 0 1
accordingly. error execute with Exception
What will be the output for following code? out printing
public class Wrapper11
{
public static void main(String[]args)
{
Long l=100;
System.out.println(l);
}
} 0 0
Carefully read the question and answer MCQ True False Compilation Runtime 1 0
accordingly. error Exception
What will be the output for following code?
public class WrapperClass12
{
public static void main(String[]args)
{
Boolean b=true;
boolean a=Boolean.parseBoolean("tRUE");
System.out.println(b==a);
}
} 0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
We can use Wrapper objects of type int, short,
char in switch case.
State True or False.
Carefully read the question and answer MCQ The number 2 4 8 64 0 0
accordingly. of bytes is
What is the number of bytes used by Java compiler
primitive long dependent 0 1 0
Carefully read the question and answer MCQ by value by reference Both by value none of these 1 0
accordingly. & reference
Data can be passed to the function ____ 0 0
Carefully read the question and answer MCQ switch for while do …. While for..each 0 0
accordingly.
Which of the following is a loop construct that
will always be executed once? 0 1 0
Carefully read the question and answer MCQ 10Bangalore 10 Compilation Runtime 0 0
accordingly. error Exception
What will be the output for following code?
public class WrapperClass1 {
public static void main(String[]args){
String s="10Bangalore";
int i=Integer.parseInt(s);
System.out.println(i);
}
} 0 1
Carefully read the question and answer MCQ compiles and compilation Runtime Error compiles and 1 0
accordingly. print 3 error prints 12
What will be the output for following code?
public class Wrapper2 {
public static void main(String[]args){
Byte b=1;
Byte a=2;
System.out.println(a+b);
}
} 0 0
Carefully read the question and answer MCQ True False compilation None of the 0 1
accordingly. error listed options
What will be the output for following code?
public class WrapperClass1 {
public static void main(String[]args){
Integer i=new Integer(10);
Integer j=new Integer(10);
System.out.println(i==j);
}
} 0 0
Carefully read the question and answer MCQ 10.98730.765 10.9873.765 Compilation 10.987 1 0
accordingly. error
The result of 10.987+”30.765” is
_________________. 0 0
Carefully read the question and answer MCQ compilation 0,6 6,0 0,5 0 1
accordingly. error
What will be the output for following code?
public class While {
static int i;
public static void main(String[]args){
System.out.println(i);
while(i<=5){
i++;
}
System.out.println(i);
}
} 0 0
Carefully read the question and answer MCQ A,Z a,z 91,97 97,91 0 0
accordingly.
What will be the output for following code?
public class While {
public static void main(String[]args){
int a='A';
int i=a+32;
while(a<='Z'){
a++;
}
System.out.println(i);
System.out.println(a);
}
} 0 1
Carefully read the question and answer MCQ break Jump exit goto escape 1 0
accordingly.
The ______ statement is used inside the switch
to terminate a Statement sequence 0 0 0
Carefully read the question and answer MCQ Primitive Wrapper Primitive Wrapper None Of the 1 0
accordingly. Wrapper Primitive options
What will be the output of below code?
public class Test {
public static void main(String[] args) {
int i = 1;
Integer I = new Integer(i);
method(i);
method(I);
}
static void method(Integer I) {
System.out.print(" Wrapper");
}
static void method(int i) {
System.out.print(" Primitive");
}
} 0 0 0
Carefully read the question and answer MCQ The class The number 1 The number 2 The number 3 The program 0 1
accordingly. compiles and gets printed gets printed gets printed generates a
What happens when the following code is runs, but does with with with compilation
compiled and run. Select the one correct not print AssertionError AssertionError AssertionError error.
answer. anything.
for(int i = 1; i < 3; i++)
for(int j = 3; j >= 1; j--)
assert i!=j : i; 0 0 0
Carefully read the question and answer MCQ default break continue new none 0 1
accordingly.
Each case in switch statement should end with
________ statement 0 0 0
Carefully read the question and answer MCQ executeUpdat executeQuery execute() noexecute() 0 1
accordingly. e() ()
Which method executes a simple query and
returns a single Result Set object? 0 0
Carefully read the question and answer MCQ ResultSet Parametrized PreparedState Condition 0 0
accordingly. ment
Which object allows you to execute
parametrized queries? 1 0
Carefully read the question and answer MCQ 1&2 3&4 2&3 1&4 2&4 0 0
accordingly.
Which statements about JDBC are true?
1.JDBC has 5 types of Drivers
2.JDBC stands for Java DataBase Connectivity
3.JDBC is an API to access relational
databases, spreadsheets and flat files
4.JDBC is an API to bridge the object-relational
mismatch between OO programs and relational
databases
1 0 0
Carefully read the question and answer MCQ PreparedState Parameterize Parameterize All kinds of 1 0
accordingly. ment dStatement dStatement Statements
Which type of Statement can execute and (i.e. which
parameterized queries? CallableState implement a
ment sub interface
of Statement) 0 0
Carefully read the question and answer MCQ Connection Connection Connection Connection 0 1
accordingly. cn=DriverMan cn=DriverMan cn=DriverMan cn=DriverMan
You are using JDBC-ODBC bridge driver to ager.getConn ager.getConn ager.getConn ager.getConn
establish a connection with a database. You ection("jdbc:o ection("jdbc:o ection("jdbc:o ection("jdbc:o
have created a DSN Mydsn. Which statement dbc"); dbc:Mydsn", dbc dbc:dsn"
will you use to connect to the database? "username", ","username", ,"username",
"password"); "password"); "password"); 0 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
The method Class.forName() is a part of JDBC
API. State True or False.
Carefully read the question and answer MCQ putConnection setConnection Connection() getConnetion( 0 0
accordingly. () () )
Connection object can be initialized using
which method of the Driver Manager class? 0 1
Carefully read the question and answer MCQ Type 1 driver Type 2 driver Type 3 driver Type 4 driver 0 0
accordingly.
Which type of driver converts JDBC calls into
the network protocol used by the database
management system directly? 0 1
Carefully read the question and answer MCQ The code will The code will Class.forNam "SELECT * 0 1
accordingly. not compile as display all e must be FROM
Which of the following is true with respect to no try catch values in mentioned Person" query
code given below? block column after must be
import java.sql.*; specified named Connection passed as
public class OracleDemo column1 statement parameter to
{ con.createStat
public static void main(String [] args) throws ement()
SQLException,ClassNotFoundException
{
Class.forName("oracle.jdbc.driver.OracleDriver
");
Connection
con=DriverManager.getConnection("jdbc:oracl
e:thin:@PC188681:1521:training","scott","tiger"
);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT *
FROM Person");
while(rs.next())
{
System.out.println(rs.getString("column1"));
}
}
}
0 0
Carefully read the question and answer MCQ JDBC drivers ODBC drivers Both A and B None of the 0 1
accordingly. above
The JDBC-ODBC Bridge driver translates the
JDBC API to the ODBC API and used with
which of the following: 0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Type 1 & Type 3 driver types are not vendor
specific implementation of Java driver. State
True or False
Carefully read the question and answer MCQ executeUpdat executeQuery execute() noexecute() 0 0
accordingly. e() ()
Which method executes an SQL statement that
may return multiple results? 1 0
Carefully read the question and answer MCQ connection.sql db.sql pkg.sql java.sql 0 0
accordingly.
Which package contains classes that help in
connecting to a database, sending SQL
statements to the database, and processing the
query results 0 1
Carefully read the question and answer MCQ initialized started paused stopped 1 0
accordingly.
What is the state of the parameters of the
PreparedStatement object when the user clicks
on the Query button? 0 0
Carefully read the question and answer MCQ java.util.Date java.sql.Date java.sql.Time java.sql.Times 0 0
accordingly. tamp
Which of the following listed option gives the
valid type of object to store a date and time
combination using JDBC API? 0 1
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
If your JDBC Connection is in auto-commit
mode, which it is by default, then every SQL
statement is committed to the database upon
its completion. State True or False.
Carefully read the question and answer MCQ Call method Call method Call method Call method 1 0
accordingly. execute() on a executeProce execute() on a run() on a
How can you execute a stored procedure in the CallableState dure() on a StoredProced ProcedureCo
database? ment object Statement ure object mmand object
object 0 0
Carefully read the question and answer MCQ ResultSet Parametrized TableStateme Condition 1 0
accordingly. nt
Which object provides you with methods to
access data from the table? 0 0
Carefully read the question and answer MCQ DDL To execute DDL Support for 1 0
accordingly. statements DDL statements DDL
What is correct about DDL statements? are treated as statements, cannot be statements
normal SQL you have to executed by will be a
statements, install making use of feature of a
and are additional JDBC, you future release
executed by support files should use the of JDBC
calling the native
execute() database tools
method on a for this.
Statement (or
a sub
interface
thereof) object
0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
executeUpdate() & execute() are valid methods
that can be used for executing DDL
statements. State True or False
Carefully read the question and answer MCQ ODBC written ODBC written ODBC written ODBC written 1 0
accordingly. in C language in C# in C++ in Basic
A Java program cannot directly communicate language language language
with an ODBC driver because of which of the
following: 0 0
Carefully read the question and answer MCQ Both Statement A Statement A Both 1 0
accordingly. Statement A is True and is False and Statements A
Consider the following statements: and Statement Statement B Statement B and B are
Statement A: The PreparedStatement object B are True. is False. is True. False.
enables you to execute parameterized queries.
Statement B: The SQL query can use the
placeholders which are replaced by the INPUT
parameters at runtime.
Which of the following option is True with
respect to the above statements?
0 0
Carefully read the question and answer MCQ java.jdbc and java.jdbc and java.sql and java.rdb and 0 0
accordingly. javax.jdbc java.jdbc.sql javax.sql javax.rdb
Which packages contain the JDBC classes? 1 0
Carefully read the question and answer MCQ putString() insertString() setString() setToString() 0 0
accordingly.
Which method sets the query parameters of
the PreparedStatement Object? 1 0
Carefully read the question and answer MCQ Statement PreparedState CallableState None of the 0 1
accordingly. ment ment listed options
Consider you are developing a JDBC
application, where you have to retrieve the
Employee information from the database table
based on Employee id value passed at runtime
as parameter. Which best statement API you
will use to execute parameterized SQL
statement at runtime? 0 0
Carefully read the question and answer MCQ java.util.Hash java.util.Linke java.util.List java.util.Array 0 0
accordingly. Set dHashSet List
Which collection class allows you to grow or
shrink its size and provides indexed access to
its elements, but whose methods are not
synchronized? 0 1
Carefully read the question and answer MCQ ResultSet ResultSetMet DataSource Statement 0 1
accordingly. aData
Consider you are developing a JDBC
application, where you have to retrieve
Employee table schema information like table
columns name, columns field length and data
type etc. Which API you will use to retrieve
table schema information? 0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
In Thread implementation methods like wait(),
notify(), notifyAll() should be used in
synchronized context .
State true or false
Carefully read the question and answer MCQ Reader and InputStream Collection None of the 1 0
accordingly. Writer Stream and APIs listed options
Consider you are developing an application APIs OutputStream
where you have to store and retrieve data in Stream APIs
character format in file. Which API you will use
to store and retrieve the data in character
format? 0 0
Carefully read the question and answer MCQ TreeMap HashMap LinkedHashM Non of the 1 0
accordingly. ap listed options
Which of the following provides an efficient
means of storing key/value pairs in sorted
order, and allows rapid retrieval? 0 0
Carefully read the question and answer MCQ Statement PreparedState CallableState None of the 0 0
accordingly. ment ment listed options
Consider you are developing a JDBC
application, where you have to retrieve
quarterly report from database by executing
database store procedure created by database
developer. Which statement API you will use to
execute store procedure and retrieve ResultSet
information? 1 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Interfaces are mainly used to expose behavior
or functionality not the implementation code.
State true or false
Carefully read the question and answer MCQ Reduces Allows Reduces Fosters All of the 0 0
accordingly. programming interoperabilit effort to learn software listed options
Select the advantages of using Collection API’s effort y among and to use reuse
in java application development. unrelated new APIs
APIs 0 0 1
Carefully read the question and answer MCA If the equals() If the equals() If the If the 0 0.5
accordingly. method method hashCode() hashCode()
Which statements are true about comparing returns true, returns false, comparison comparison
two instances of the same class, given that the the the == returns == returns
equals() and hashCode() methods have been hashCode() hashCode() true, the true, the
properly overridden? comparison comparison equals() equals()
== might == might method must method might
return false return true return true return true 0 0.5
Carefully read the question and answer MCQ Declare the Declare the Declare the None of the 0 0
accordingly. ProgrammerA ProgrammerA ProgrammerA listed options
Consider you are developing java application in nalyst class nalyst class nalyst class
a team consists of 20 developers and you have has abstract has private has final
been asked to develop class by Name
ProgrammerAnalyst and to ensure that other
developers in team use ProgrammerAnalyst
class only by creating object and team member
should not be given provision to inherit and
modify any functionality written in
ProgrammerAnalyst class using inheritance.
How do you achieve this requirement in
development scenario? 1 0
Carefully read the question and answer MCQ finalization Serialization Synchronizati Deserializatio 0 1
accordingly. on n
Consider a development scenario where you
want to write the object data into persistence
storage devices (like file, disk etc.).Using which
of the below concept you can achieve the given
requirement? 0 0
Carefully read the question and answer MCQ By By Two thread in A thread can 0 0
accordingly. multithreading multitasking Java can have exist only in
Which of the following statement is incorrect? CPU’s idle CPU’s idle same priority two states,
time is time is running and
minimized, minimized, blocked.
and we can and we can
take take
maximum use maximum use
of it. of it. 0 1
Carefully read the question and answer MCQ Using Thread Using object Using object None of the 1 0
accordingly. Synchronizati serialization deserialization listed options
Consider you are developing an ATM on
application for ABC Bank using java
application. Several account holders of ABC
Bank have opted for add-on cards. There is a
chance that two users may access the same
account at same time and do transaction
simultaneously knowingly or unknowingly from
different ATM machine from same or different
bank branches. As developer you have to
ensure that when one user login to account
until he finishes his transaction account should
be locked to other users who are trying access
the same account. How do you implement
given requirement programmatically using
java? 0 0
Carefully read the question and answer MCQ main method finalize static block private 0 0
accordingly. method code method
Which of these is executed first before
execution of any other thing takes place in a
program? 1 0
Carefully read the question and answer MCQ Check Check Check None of the 1 0
accordingly. whether you whether you whether you listed options
Consider you are trying to persist or store have have have marked
object of Customer class using implemented implemented Customer
ObjectOutputStream class in java. When you Customer Customer class methods
are trying to persist customer object data java class with class with with
code is throwing runtime exception without Serializable Externalizable synchronized
persisting object information. Please suggest interface interface keyword
what is the key important factor you have
consider in code in order to persist customer
object data. 0 0
Carefully read the question and answer MCQ java.lang.Strin java.lang.Dou java.lang.Strin java.lang.Char 0 0
accordingly. g ble gBuffer acter
Which class does not override the equals() and
hashCode() methods, inheriting them directly
from class Object? 1 0
Carefully read the question and answer MCQ Any one will Both of them None of them It is 0 0
accordingly. be executed will be will be dependent on
What will happen if two thread of same priority first executed executed the operating
are called to be processed simultaneously? lexographicall simultaneousl system.
y y 0 1
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
In Thread implementation making method
synchronized is always better in order to
increase application performance rather than
using synchronize block to synchronize certain
block of statements written in java inside the
method.
State True or False.
Carefully read the question and answer MCQ Generics Generics and When All of the 0 0
accordingly. provide type parameterized designing mentioned
Which of the following is incorrect statement safety by types your own
regarding the use of generics and shifting more eliminate the collections
parameterized types in Java? type checking need for down class (say, a
responsibilitie casts when linked list),
s to the using Java generics and
compiler. Collections. parameterized
types allow
you to achieve
type safety
with just a
single class
definition as
opposed to
defining
multiple
classes.
1 0
Carefully read the question and answer MCQ Mark Mark Make Make 1 0
accordingly. Employee Employee Employee Employee
Consider the development scenario where you class with class with class methods class methods
have created Employee class with abstract final keyword private public
implementation code and as per the project keyword
requirement you have to ensure that developer
in team reusing code written in Employee class
only using inheritance by extending the
employee class but not by creating the instance
of Employee object directly. Please suggest the
solution to implement given requirement?
0 0
Carefully read the question and answer MCQ java.util.Map java.util.Set java.util.List java.util.Collec 0 1
accordingly. tion
You need to store elements in a collection that
guarantees that no duplicates are stored and all
elements can be accessed in natural order.
Which interface provides that capability?
0 0
Carefully read the question and answer MCQ Implement Implement Implement None of the 0 1
accordingly. using Arrays using using file listed options
Consider you are developing shopping cart Collection API’s
application you have to store details of items API’s.
purchased by the each customer in
intermediate memory before storing purchase
details in actual database permanently note
that number of different items purchased by
customer is not definite it may vary. How do
you implement given requirement using java
considering best performance of the
application? 0 0