Core Java Assessment MCQS
Core Java Assessment MCQS
Core Java Assessment MCQS
class Sample
{int a,b;
Sample()
{ a=1; b=2;
System.out.println(a+"\t"+b);
}
Sample(int x)
{ this(10,20);
a=b=x;
System.out.println(a+"\t"+b);
}
Sample(int a,int b)
{ this();
this.a=a;
this.b=b;
System.out.println(a+"\t"+b);
}
}
class This2
{ public static void main(String args[])
Access {
Specifiers Sample s1=new Sample (100);
Constructors }
Methods } 100 100 1 2 1 2 100 100 10 20 1 2 100 1 2 10 20 100
NewQB What is the Output of the Program? MCQ 10 20 10 20 100 100 0 0 0 1
Consider the following code and choose the
Access correct option:
Specifiers class A{ private static void display() Compiles and Compiles but
Constructors { System.out.print("Hi");} throw run doesn't
Methods public static void main(String ar[]){ Compiles and time display Compilation
NewQB display();}} MCQ display Hi exception anything fails 1 0 0 0
Consider the following code and choose the
Access correct option: code
Specifiers package aj; class A{ protected int j; } code compiles but
Constructors package bj; class B extends A compiles fine will not
Methods { public static void main(String ar[]){ and will display compliation j can not be
NewQB System.out.print(new A().j=23);}} MCQ display 23 output error initialized 0 0 1 0
Consider the following code and choose the
Access correct option:
Specifiers class A{ int z; A(int x){z=x;} } Compiles but
Constructors class B extends A{ throws run Compiles and
Methods public static void main(String arg){ Compilation time displays None of the
NewQB new B();}} MCQ error exception nothing listed options 1 0 0 0
class Test{
static void method(){
this.display();
}
static display(){
System.out.println(("hello");
}
public static void main(String[] args){
Access new Test().method();
Specifiers }
Constructors }
Methods consider the code above & select the proper compiles but does not
NewQB output from the options. MCQ hello Runtime Error no output compile 0 0 0 1
Access public static void main(String[] args) { String: String int: 27,
Specifiers print("String first", 11); first, int: 11 String: Int
Constructors print(99, "Int first"); int: 99, first String:
Methods } String: Int String first, Compilation Runtime
NewQB }What would be the output? MCQ first int: 27 Error Exception 1 0 0 0
class Order{
Order(){
System.out.println("Cat");
}
public static void main(String... Args){
System.out.println("Ant");
}
static{
System.out.println("Dog");
}
Access {
Specifiers System.out.println("Man");
Constructors }}
Methods consider the code above & select the proper Dog Man Cat
NewQB output from the options. MCQ Dog Ant Ant Man Dog Ant Dog Man Ant 1 0 0 0
Consider the following code and choose the
Access correct option:
Specifiers class A{ private void display() Compiles but Compiles and
Constructors { System.out.print("Hi");} doesn't throws run
Methods public static void main(String ar[]){ display time Compilation Compiles and
NewQB display();}} MCQ anything exception fails displays Hi 0 0 1 0
Consider the following code and choose the
correct option:
public class MyClass {
public static void main(String arguments[]) {
amethod(arguments);
}
public void amethod(String[] arguments) {
Access System.out.println(arguments[0]);
Specifiers System.out.println(arguments[1]);
Constructors }
Methods } prints Hi Compiler Runs but no
NewQB Command Line arguments - Hi, Hello MCQ Hello Error output Runtime Error 0 1 0 0
package QB;
class Sphere {
protected int methodRadius(int r) {
System.out.println("Radious is: "+r);
return 0;
}
}
package QB;
public class MyClass {
public static void main(String[] args) {
double x = 0.89;
Access Sphere sp = new Sphere();
Specifiers // Some code missing
Constructors }
Methods } to get the radius value what is the code of methodRadiu sp.methodRa Nothing to Sphere.meth
NewQB line to be added ? MCQ s(x); dius(x); add odRadius(); 0 1 0 0
class One{
int var1;
One (int x){
var1 = x;
}}
class Derived extends One{
int var2;
void display(){
System.out.println("var
1="+var1+"var2="+var2);
}}
class Main{
public static void main(String[] args){
Access Derived obj = new Derived();
Specifiers obj.display(); compiles
Constructors }} successfully
Methods consider the code above & select the proper but runtime
NewQB output from the options. MCQ 0,0 error compile error none of these 0 0 1 0
Consider the following code and choose the
correct option:
class Test{ private void display(){
Access System.out.println("Display()");}
Specifiers private static void show() { display(); Compiles and Compiles but
Constructors System.out.println("show()");} prints throws
Methods public static void main(String arg[]){ Compiles and Display() runtime Compilation
NewQB show();}} MCQ prints show() show() exception error 0 0 0 1
Consider the following code and choose the
best option:
Access class Super{ int x; Super(){x=2;}}
Specifiers class Sub extends Super { void displayX(){
Constructors System.out.print(x);} Compiles and
Methods public static void main(String args[]){ Compilation runs without Compiles and Compiles and
NewQB new Sub().displayX();}} MCQ error any output display 2 display 0 0 0 1 0
class One{
int var1;
One (int x){
var1 = x;
}}
class Derived extends One{
int var2;
Derived(){
super(10);
var2=10;
}
void display(){
System.out.println("var1="+var1+" ,
var2="+var2);
}}
class Main{
public static void main(String[] args){
Access Derived obj = new Derived();
Specifiers obj.display();
Constructors }}
Methods consider the code above & select the proper var1=10 ,
NewQB output from the options. MCQ var2=10 0,0 compile error runtime error 1 0 0 0
class Meal {
Meal() {
System.out.println("Meal()");
}
}
class Cheese {
Cheese() {
System.out.println("Cheese()");
}
}
class Lunch extends Meal {
Lunch() {
System.out.println("Lunch()");
}
}
class PortableLunch extends Lunch {
PortableLunch() {
System.out.println("PortableLunch()");
}
}
class Sandwich extends PortableLunch {
private Cheese c = new Cheese();
public Sandwich() {
System.out.println("Sandwich()");
} Meal() Meal() Cheese()
Access } Meal() Cheese() Lunch() Sandwich()
Specifiers public class MyClass7 { Lunch() Lunch() PortableLunc Meal()
Constructors public static void main(String[] args) { PortableLunc PortableLunc h() Lunch()
Methods new Sandwich(); h() Cheese() h() Sandwich() PortableLunc
NewQB } MCQ Sandwich() Sandwich() Cheese() h() 1 0 0 0
Consider the following code and choose the
correct option:
class A{ int a; A(int a){a=4;}}
Access class B extends A{ B(){super(3);} void
Specifiers displayA(){
Constructors System.out.print(a);}
Methods public static void main(String args[]){ compiles and compilation Compiles and Compiles and
NewQB new B().displayA();}} MCQ display 0 error display 4 display 3 1 0 0 0
Given the following code what will be output?
public class Pass{
static int j=20;
public static void main(String argv[]){
int i=10;
Pass p = new Pass();
p.amethod(i);
System.out.println(i);
System.out.println(j);
}
Error:
Access public void amethod(int x){ amethod
Specifiers x=x*2; parameter
Constructors j=j*2; does not
Methods } match
NewQB } MCQ variable 20 and 40 10 and 40 10, and 20 0 0 1 0
The compiler
will
automatically The program
Access change the The compiler will compile
Specifiers What will happen if a main() method of a private will find the The program successfully,
Constructors "testing" class tries to access a private variable to a error and will will compile but the .class
Methods instance variable of an object using dot public not make and run file will not
NewQB notation? MCQ variable a .class file successfully run correctly 0 1 0 0
class Order{
Order(){
System.out.println("Cat");
}
public static void main(String... Args){
Order obj = new Order();
System.out.println("Ant");
}
static{
System.out.println("Dog");
}
Access {
Specifiers System.out.println("Man");
Constructors }}
Methods consider the code above & select the proper Man Dog Cat Cat Ant Dog Dog Man Cat
NewQB output from the options. MCQ Ant Man Ant compile error 0 0 1 0
abstract class MineBase {
abstract void amethod();
static int i;
} Compilation
public class Mine extends MineBase { Error occurs
public static void main(String argv[]){ and to avoid
Access int[] ar=new int[5]; them we
Specifiers for(i=0;i < ar.length;i++) A Sequence A Sequence need to
Constructors System.out.println(ar[i]); of 5 zero's of 5 one's will declare Mine
Methods } will be printed be printed IndexOutOfB class as
NewQB } MCQ like 0 0 0 0 0 like 1 1 1 1 1 oundes Error abstract 0 0 0 1
public class Q {
Access public static void main(String argv[]) { Compiler
Specifiers int anar[] = new int[] { 1, 2, 3 }; Error: anar is Compiler
Constructors System.out.println(anar[1]); referenced Error: size of
Methods } before it is array must be
NewQB } MCQ initialized 2 1 defined 0 1 0 0
Access
Specifiers
Constructors
Methods A constructor may return value including
NewQB class type MCQ true false 0 1
Consider the following code and choose the
correct option:
Access package aj; class S{ int roll =23;
Specifiers private S(){} }
Constructors package aj; class T
Methods { public static void main(String ar[]){ Compilation Compiles and Compiles and Compiles but
NewQB System.out.print(new S().roll);}} MCQ error display 0 display 23 no output 1 0 0 0
It is not
possible to
declare a
public class MyAr { static variable
public static void main(String argv[]) { in side of non
MyAr m = new MyAr(); static method
m.amethod(); or instance
} method.
public void amethod() { Because
Access static int i1; Compile time Static
Specifiers System.out.println(i1); error because variables are
Constructors } i has not Compilation class level
Methods } been and output of dependencies
NewQB What is the Output of the Program? MCQ initialized null . 0 0 0 1
public class c1 {
private c1()
{
System.out.println("Hello");
}
public static void main(String args[])
{
Access c1 o1=new c1(); It is not Can't create
Specifiers } possible to object
Constructors } declare a because
Methods constructor Compilation constructor is
NewQB What is the output? MCQ Hello private Error private 1 0 0 0
Access
Specifiers Which modifier indicates that the variable
Constructors might be modified asynchronously, so that all
Methods threads will get the correct value of the
NewQB variable. MCQ synchronized volatile transient default 0 1 0 0
class A {
int i, j;
A(int a, int b) {
i = a;
j = b;
}
void show() {
System.out.println("i and j: " + i + " " + j);
}
}
class B extends A {
int k;
Given:
public static Collection get() {
Collection sorted = new LinkedList();
sorted.add("B"); sorted.add("C");
sorted.add("A");
return sorted;
}
public static void main(String[] args) {
for (Object obj: get()) {
System.out.print(obj + ", ");
} An exception
Collections_u } Compilation is thrown at
til_NewQB What is the result? MCQ A, B, C, B, C, A, fails. runtime. 0 1 0 0
Given:
public static Iterator reverse(List list) {
Collections.reverse(list);
return list.iterator();
}
public static void main(String[] args) {
List list = new ArrayList();
list.add("1"); list.add("2"); list.add("3");
for (Object obj: reverse(list))
System.out.print(obj + ", "); The code
Collections_u } Compilation runs with no
til_NewQB What is the result? MCQ 3, 2, 1, 1, 2, 3, fails. output. 0 0 1 0
Which collection class allows you to grow or
shrink its size and provides indexed access
to
Collections_u its elements, but its methods are not java.util.Hash java.util.Linke java.util.Array java.util.Vect
til_NewQB synchronized? MCQ Set dHashSet java.util.List List or 0 0 0 1 0
Given:
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
System.out.println(set.equals(set2));
Collections_u } Compile time Runtime
til_NewQB } What is the result of given code? MCQ true false error Exception 0 1 0 0
A)Property files help to decrease coupling
B) DateFormat class allows you to format
dates and times with customized styles.
C) Calendar class allows to perform date
calculation and conversion of dates and times
Collections_u between timezones. A and B is A and D is A and C is B and D is
til_NewQB D) Vector class is not synchronized MCQ TRUE TRUE TRUE TRUE 0 0 1 0
Collections_u Which interface does java.util.Hashtable Java.util.Colle
til_NewQB implement? MCQ Java.util.Map Java.util.List Java.util.Table ction 1 0 0 0
Object get(Object key) - What does this
Collections_u method return if the key is not found in the none of the
til_NewQB Map? MCQ -1 null listed options 0 0 1 0
Given:
import java.util.*;
Given:
public class Venus {
public static void main(String[] args) {
int [] x = {1,2,3};
int y[] = {4,5,6};
new Venus().go(x,y);
}
void go(int[]... z) {
for(int[] a : z)
System.out.print(a[0]);
Collections_u }
til_NewQB } What is the result? MCQ 123 12 14 1 0 0 1 0
1) TreeSet
2) HashMap
Collections_u 3) LinkedList
til_NewQB 4) an array MCQ 1 2 3 4 0 0 0 1
What will be the output of following code?
class Test{
public static void main(String args[]){
TreeSet<Integer> ts=new
TreeSet<Integer>();
ts.add(2);
ts.add(3);
ts.add(7);
ts.add(5);
SortedSet<Integer> ss=ts.subSet(1,7);
ss.add(4);
Collections_u ss.add(6);
til_NewQB System.out.print(ss);}} MCQ [2,3,7,5] [2,3,7,5,4,6] [2,3,4,5,6,7] [2,3,4,5,6] 0 0 0 1
Given:
public class Test {
public enum Dogs {collie, harrier};
public static void main(String [] args) {
Dogs myDog = Dogs.collie;
switch (myDog) {
case collie:
System.out.print("collie ");
Control case harrier:
structures System.out.print("harrier ");
wrapper }
classes auto }
boxing } Compilation
NewQB What is the result? MCQ collie harrier fails. collie harrier 0 0 0 1
Consider the following code and choose the
correct output:
Control class Test{
structures public static void main(String args[]){
wrapper boolean flag=true;
classes auto if(flag=false){
boxing System.out.print("TRUE");}else{ compilation
NewQB System.out.print("FALSE");}}} MCQ true false error Compiles 0 1 0 0
Cosider the following code and choose the
Control correct option:
structures class Test{
wrapper public static void main(String args[])
classes auto { System.out.println(Integer.parseInt("21474 NumberForm
boxing 83648", 10)); Compilation 2.147483648 atException Compiles but
NewQB }} MCQ error E9 at run time no output 0 0 1 0
Given:
public class Test {
public enum Dogs {collie, harrier, shepherd};
public static void main(String [] args) {
Dogs myDog = Dogs.shepherd;
switch (myDog) {
case collie:
System.out.print("collie ");
case default:
System.out.print("retriever ");
Control case harrier:
structures System.out.print("harrier ");
wrapper }
classes auto }
boxing } Compilation
NewQB What is the result? MCQ harrier shepherd retriever fails. 0 0 0 1
Given:
static void myFunc()
{
int i, s = 0;
for (int j = 0; j < 7; j++) {
i = 0;
do {
i++;
Control s++;
structures } while (i < j);
wrapper }
classes auto System.out.println(s);
boxing }
NewQB } What would be the result MCQ 20 21 22 23 24 0 0 1 0 0
Control
structures
wrapper
classes auto What is the range of the random number r
boxing generated by the code below?
NewQB int r = (int)(Math.floor(Math.random() * 8)) + 2; MCQ 2 <= r <= 9 3 <= r <= 10 2<= r <= 10 3 <= r <= 9 1 0 0 0
class Test{
public static void main(String[] args) {
int x=-1,y=-1;
if(++x=++y)
System.out.println("R.T. Ponting");
Control else
structures System.out.println("C.H. Gayle");
wrapper }
classes auto }
boxing consider the code above & select the proper none of the
NewQB output from the options. MCQ R.T.Ponting C.H.Gayle Compile error listed options 0 0 1 0
Given:
public class Breaker2 {
static String o = "";
public static void main(String[] args) {
z:
for(int x = 2; x < 7; x++) {
if(x==3) continue;
if(x==5) break z;
Control o = o + x;
structures }
wrapper System.out.println(o);
classes auto }
boxing }
NewQB What is the result? MCQ 2 24 234 246 0 1 0 0
Consider the following code and choose the
correct output:
Control class Test{
structures public static void main(String args[]){
wrapper int a=5;
classes auto if(a=3){
boxing System.out.print("Three");}else{ Compilation Compiles but
NewQB System.out.print("Five");}}} MCQ error Three Five no output 1 0 0 0
Given:
public class Batman {
int squares = 81;
public static void main(String[] args) {
new Batman().go();
}
void go() {
Control incr(++squares);
structures System.out.println(squares);
wrapper }
classes auto void incr(int squares) { squares += 10; }
boxing }
NewQB What is the result? MCQ 81 82 91 92 0 1 0 0
public void foo( boolean a, boolean b)
{
if( a )
{
System.out.println("A"); /* Line 5 */
}
else if(a && b) /* Line 7 */
{
System.out.println( "A && B");
}
else /* Line 11 */
{
if ( !b )
{
System.out.println( "notB") ;
}
else
{
Control System.out.println( "ELSE" ) ;
structures } If a is true If a is true If a is false If a is false
wrapper } and b is false and b is true and b is false and b is true
classes auto } then the then the then the then the
boxing output is output is "A output is output is
NewQB What would be the result? MCQ "notB" && B" "ELSE" "ELSE" 0 0 0 1
Given:
class Atom {
Atom() { System.out.print("atom "); }
}
class Rock extends Atom {
Rock(String type) { System.out.print(type); }
}
public class Mountain extends Rock {
Mountain() {
super("granite ");
Control new Rock("granite ");
structures }
wrapper public static void main(String[] a) { new
classes auto Mountain(); }
boxing } Compilation granite atom granite atom granite
NewQB What is the result? MCQ fails. granite granite atom granite 0 0 0 1
Given:
public class Barn {
public static void main(String[] args) {
new Barn().go("hi", 1);
new Barn().go("hi", "world", 2);
Control }
structures public void go(String... y, int x) {
wrapper System.out.print(y[y.length - 1] + " ");
classes auto }
boxing } Compilation
NewQB What is the result? MCQ hi hi hi world world world fails. 0 0 0 1
Consider the following code and choose the
correct option:
class Test{
Control public static void main(String args[]){ int
structures x=034;
wrapper int y=12;
classes auto int ans=x+y; Compiles but
boxing System.out.println(ans); compilation error at run
NewQB }} MCQ 40 46 error time 1 0 0 0
11. double input = 314159.26;
12. NumberFormat nf =
Control NumberFormat.getInstance(Locale.ITALIAN);
structures 13. String b;
wrapper 14. //insert code here
classes auto b= b= b= b=
boxing Which code, inserted at line 14, sets the nf.parse( inpu nf.format( inp nf.equals( inp nf.parseObjec
NewQB value of b to 314.159,26? MCQ t ); ut ); ut ); t( input ); 0 1 0 0
Consider the following code and choose the
correct option:
class Test{
public static void main(String ar[]){
TreeMap<Integer,String> tree = new
TreeMap<Integer,String>();
tree.put(1, "one");
tree.put(2, "two");
tree.put(3, "three");
Control tree.put(4,"Four");
structures System.out.println(tree.higherKey(2));
wrapper System.out.println(tree.ceilingKey(2));
classes auto System.out.println(tree.floorKey(1));
boxing System.out.println(tree.lowerKey(1));
NewQB }} MCQ 3 2 1 null 3211 2211 4211 1 0 0 0
Control Consider the following code and choose the
structures correct option:
wrapper class Test{
classes auto public static void main(String args[]){ Compiles but
boxing Long data=23; Compilation error at run None of the
NewQB System.out.println(data); }} MCQ 23 error time listed options 0 1 0 0
class AutoBox {
public static void main(String args[]) {
int i = 10;
Control Integer iOb = 100;
structures i = iOb;
wrapper System.out.println(i + " " + iOb);
classes auto } No,
boxing } whether this code work properly, if so what Compilation No, Runtime
NewQB would be the result? MCQ error error Yes, 10, 100 Yes, 100, 100 0 0 0 1
Control Consider the following code and choose the
structures correct option:
wrapper class Test{
classes auto public static void main(String args[]){
boxing Long l=0l; Compilation
NewQB System.out.println(l.equals(0));}} MCQ error true false 1 0 0 1 0
int I = 0;
outer:
while (true)
{
I++;
inner:
for (int j = 0; j < 10; j++)
{
I += j;
if (j == 3)
continue inner;
break outer;
Control }
structures continue outer;
wrapper }
classes auto System.out.println(I);
boxing
NewQB What will be thr result? MCQ 3 2 4 1 0 0 0 1
Given:
int a = 5;
int b = 5;
int c = 5;
if (a > 3)
if (b > 4)
if (c > 5)
c += 1;
else
Control c += 2;
structures else
wrapper c += 3;
classes auto c += 4;
boxing What is the value of variable c after executing
NewQB the following code? MCQ 3 5 7 9 11 0 0 0 0 1
Given:
Float pi = new Float(3.14f);
if (pi > 3) {
System.out.print("pi is bigger than 3. ");
}
else {
Control System.out.print("pi is not bigger than 3. ");
structures }
wrapper finally {
classes auto System.out.println("Have a nice day."); An exception pi is bigger
boxing } Compilation pi is bigger occurs at than 3. Have
NewQB What is the result? MCQ fails. than 3. runtime. a nice day. 1 0 0 0
Given:
public void go() {
String o = "";
z:
for(int x = 0; x < 3; x++) {
for(int y = 0; y < 2; y++) {
if(x==1) break;
if(x==2 && y==1) break z;
o = o + x + y;
Control }
structures }
wrapper System.out.println(o);
classes auto }
boxing What is the result when the go() method is
NewQB invoked? MCQ 00 0001 000120 00012021 0 0 1 0
int count = 1;
while ( ___________ )
{
System.out.print( count + " " );
count = count + 1;
}
Control System.out.println( );
structures
wrapper What condition should be used so that the
classes auto code prints:
boxing
NewQB 12345678 MCQ count < 9 count+1 <= 8 count < 8 count != 8 1 0 0 0
What will be the output of the program?
Given:
double height = 5.5;
if(height-- >= 5.0)
System.out.print("tall ");
if(--height >= 4.0)
System.out.print("average ");
Control if(height-- >= 3.0)
structures System.out.print("short ");
wrapper else
classes auto System.out.print("very short ");
boxing }
NewQB What would be the Result? MCQ tall tall short short very short average 0 1 0 0 0
Consider the following code and choose the
Control correct option:
structures class Test{
wrapper public static void main(String args[]){
classes auto String hexa = "0XFF"; Compiles but
boxing int number = Integer.decode(hexa); Compilation error at run
NewQB System.out.println(number); }} MCQ error 1515 255 time 0 0 1 0
Consider the following code and choose the
correct option:
int i = l, j = -1;
switch (i)
Control {
structures case 0, 1: j = 1;
wrapper case 2: j = 2;
classes auto default: j = 0;
boxing } Compilation
NewQB System.out.println("j = " + j); MCQ j = -1 j=0 j=1 fails 0 0 0 1
Control
structures
wrapper
classes auto Person[] p = Person p[][] =
boxing Which of the following statements about new new
NewQB arrays is syntactically wrong? MCQ Person[5]; Person p[5]; Person[] p []; Person[2][]; 0 1 0 0
import java.util.*;
class I
{
public static void main (String[] args)
{
Object i = new ArrayList().iterator();
System.out.print((i instanceof List)+",");
Control System.out.print((i instanceof Iterator)
structures +",");
wrapper System.out.print(i instanceof
classes auto ListIterator);
boxing } Prints: false, Prints: false, Prints: false, Prints: false,
NewQB } MCQ false, false false, true true, false true, true 0 0 1 0
Given:
public static void test(String str) {
int check = 4;
if (check = str.length()) {
System.out.print(str.charAt(check -= 1) +",
");
} else {
System.out.print(str.charAt(0) + ", ");
}
Control }
structures and the invocation:
wrapper test("four");
classes auto test("tee"); An exception
boxing test("to"); Compilation is thrown at
NewQB What is the result? MCQ r, t, t, r, e, o, fails. runtime. 0 0 1 0
What will be the output of the program?
Control int x = 3;
structures int y = 1;
wrapper if (x = y) /* Line 3 */
classes auto { The code
boxing System.out.println("x =" + x); Compilation runs with no
NewQB } MCQ x=1 x=3 fails. output. 0 0 1 0
import java.util.SortedSet;
import java.util.TreeSet;
When an
exception When no
occurs then a exception
part of try occurs then
block will complete try
Used to execute one finally block block and
release the appropriate will never finally block
resources catch block execute when will execute
Exception_ha which are Writing finally and finally no but no catch
ndling_NewQ Which are true with respect to finally block? obtained in block is block will be exceptions block will
B (Choose THREE) MCA try block. optional. executed. are there. execute. 0.25 0.25 0.25 0 0.25
Given:
public void testIfA() {
if (testIfB("True")) {
System.out.println("True");
} else {
System.out.println("Not true");
}
}
public Boolean testIfB(String str) {
return Boolean.valueOf(str);
Exception_ha } An exception
ndling_NewQ What is the result when method testIfA is is thrown at
B invoked? MCQ true Not true runtime. none 1 0 0 0
A thread will
resume Both wait()
The wait() execution as The notify() and notify()
Deadlock will method is soon as its method is must be
Exception_ha not occur if overloaded to sleep overloaded to called from a
ndling_NewQ Which of the following statements are true? wait()/notify() accept a duration accept a synchronized
B (Choose TWO) MCA is used duration expires. duration context. 0 0.33 0.33 0 0.33
A method
declaring that
it throws a
If an An overriding certain Finally blocks
exception is method must exception are executed
not caught in declare that it The main() class may if,an
a method,the throws the method of a throw exception
method will same program can instances of gets thrown
terminate and exception declare that it any subclass while inside
Exception_ha normal classes as throws of that the
ndling_NewQ execution will the method it checked exception correspondin
B Choose TWO correct options: MCA resume overrides exception class g try block 0 0 0.5 0.5 0
Which four can be thrown using the throw
statement?
1.Error
2.Event
3.Object
Exception_ha 4.Throwable
ndling_NewQ 5.Exception
B 6.RuntimeException MCQ 1, 2, 3 and 4 2, 3, 4 and 5 1, 4, 5 and 6 2, 4, 5 and 6 0 0 1 0
class X implements Runnable
{
public static void main(String args[])
{
/* Missing code? */
} X run = new
public void run() {} Thread t = X(); Thread t
Exception_ha } Thread t = new = new Thread t =
ndling_NewQ Which of the following line of code is suitable new Thread(X); Thread(run); new Thread();
B to start a thread ? MCQ Thread(X); t.start(); t.start(); x.run(); 0 0 1 0
Given:
class X { public void foo()
{ System.out.print("X "); } }
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic
Exception_ha Exception");
ndling_NewQ } compilation ArithmeticEx
B System.out.println("finished"); MCQ finished Exception fails ception 0 0 1 0
Exception_ha
ndling_NewQ
B Which of the following methods are static? MCA start() join() yield() sleep() 0 0 0.5 0.5
static
methods can static
static be called methods do
methods are using an not have
difficult to object static direct access
maintain, reference to methods are to non-static
because you an object of always methods
can not the class in public, which are
Exception_ha change their which this because they defined inside
ndling_NewQ Which of the following statements regarding implementati method is are defined at the same
B static methods are correct? (2 answers) MCA on. defined. class-level. class. 0 0.5 0 0.5
class Test{
public static void main(String[] args){
try{
Integer.parseInt("1.0");
}
catch(Exception e){
System.out.println("Exception occurred");
}
catch(RuntimeException ex){
System.out.println("RuntimeException");
} Exception
Exception_ha }} occurred
ndling_NewQ consider the code above & select the proper Exception RuntimeExce RuntimeExce does not
B output from the options. MCQ occurred ption ption compile 0 0 0 1
1.notify();
2.notifyAll();
3.isInterrupted();
4.synchronized();
5.interrupt();
Exception_ha 6.wait(long msecs);
ndling_NewQ 7.sleep(long msecs);
B 8.yield(); MCQ 1, 2, 4 2, 4, 5 1, 2, 6 2, 3, 4 0 0 1 0
In the given code snippet
try { int a = Integer.parseInt("one"); }
what is used to create an appropriate catch
block? (Choose all that apply.)
A. ClassCastException
Exception_ha B. IllegalStateException
ndling_NewQ C. NumberFormatException ClassCastEx NumberForm IllegalStateEx IllegalArgume
B D. IllegalArgumentException MCA ception atException ception ntException 0 0.5 0 0.5
class Trial{
public static void main(String[] args){
try{
System.out.println("One");
int y = 2 / 0;
System.out.println("Two");
}
catch(RuntimeException ex){
System.out.println("Catch");
}
finally{
Exception_ha System.out.println("Finally");
ndling_NewQ } One Two One Catch One Two
B }} MCQ Catch Finally One Catch Finally Catch 0 0 1 0
Given:
class X implements Runnable
{
public static void main(String args[])
{
/* Some code */
} X run = new
public void run() {} X(); Thread t Thread t =
Exception_ha } = new Thread t = Thread t = new
ndling_NewQ Which of the following line of code is suitable Thread(run); new new Thread(); Thread(X);
B to start a thread ? MCQ t.start(); Thread(X); x.run(); t.start(); 1 0 0 0
Variables can
If a class has be protected
synchronized from
code, concurrent
multiple access
A static threads can problems by When a
method still access marking them thread
Exception_ha cannot be the with the sleeps, it
ndling_NewQ synchronized nonsynchroni synchronized releases its
B Which statement is true? MCQ . zed code. keyword. locks 0 1 0 0
Except in
An Error that case of VM
might be shutdown, if a
Multiple thrown in a try block
catch method must starts to
A try statements be declared execute, a
statement can catch the as thrown by correspondin
must have at same class that method, g finally block
Exception_ha least one of exception or be handled will always
ndling_NewQ correspondin more than within that start to
B Choose the correct option: MCQ g catch block once. method. execute. 0 0 0 1
class PropagateException{
public static void main(String[] args){
try{
method();
System.out.println("method() called");
}
catch(ArithmeticException ex){
System.out.println("Arithmetic Exception");
}
catch(RuntimeException re){
System.out.println("Runtime Exception");
}}
static void method(){
int y = 2 / 0; Arithmetic
Exception_ha }} Exception
ndling_NewQ consider the code above & select the proper Arithmetic Runtime Runtime compilation
B output from the options. MCQ Exception Exception Exception error 1 0 0 0
Given:
static void test() {
try {
String x = null;
System.out.print(x.toString() + " ");
}
finally { System.out.print("finally "); }
}
public static void main(String[] args) {
try { test(); }
catch (Exception ex)
Exception_ha { System.out.print("exception "); }
ndling_NewQ } Compilation finally
B What is the result? MCQ null fails. exception finally 0 0 1 0
3. package pkgB;
4. import pkgA.*;
5. public class Def {
6. public static void main(String[] args) {
7. Abc f = new Abc();
8. System.out.print(" " + f.a);
9. System.out.print(" " + f.b);
10. System.out.print(" " + f.c);
11. }
Exception_ha 12. } Compilation Compilation Compilation
ndling_NewQ What is the result when the second program 5 followed by fails with an fails with an fails with an
B is run? (Choose all that apply) MCA 567 an exception error on line 7 error on line 8 error on line 9 0 0 0 0.5 0.5
Consider the following code:
System.out.print("Start ");
try
{
System.out.print("Hello world");
throw new FileNotFoundException();
}
System.out.print(" Catch Here "); /* Line 7 */
catch(EOFException e)
{
System.out.print("End of file exception");
}
catch(FileNotFoundException e)
{
System.out.print("File not found");
}
Code output:
given that EOFException and Code output: Code output: Start Hello
Exception_ha FileNotFoundException are both subclasses Start Hello Start Hello world Catch
ndling_NewQ of IOException. If this block of code is pasted The code will world File Not world End of Here File not
B in a method, choose the best option. MCQ not compile. Found file exception. found. 1 0 0 0
Any
Any statement
catch(X x) statement that can
can catch that can throw an
subclasses of The Error throw an Exception
Exception_ha X where X is class is a Error must be must be
ndling_NewQ a subclass of RuntimeExce enclosed in a enclosed in a
B Which of the following statements is true? MCQ Exception. ption. try block. try block. 1 0 0 0
Consider the following code and choose the
Exception_ha correct option:
ndling_NewQ int array[] = new int[10]; compiles does not none of the
B array[-1] = 0; MCQ successfully compile runtime error listed options 0 0 1 0
What will be the output of the program?
Given:
11. class A {
12. public void process()
{ System.out.print("A,"); }
13. class B extends A {
14. public void process() throws IOException {
15. super.process();
16. System.out.print("B,");
17. throw new IOException();
18. }
19. public static void main(String[] args) {
20. try { new B().process(); }
21. catch (IOException e) Compilation Compilation
Exception_ha { System.out.println("Exception"); } fails because fails because
ndling_NewQ 22. } A,B,Exceptio of an error in of an error in
B What is the result? MCQ Exception n line 20. line 14. 0 0 0 1
The notify()
The notifyAll() The notify() method
method must To call method is causes a
be called sleep(), a defined in thread to
Exception_ha from a thread must class immediately
ndling_NewQ synchronized own the lock java.lang.Thre release its
B Which statement is true? MCQ context on the object ad locks. 1 0 0 0
class Trial{
public static void main(String[] args){
try{
System.out.println("Try Block");
}
finally{
Exception_ha System.out.println("Finally Block");
ndling_NewQ } Try Block Finally Block
B }} MCQ Try Block Finally Block Finally Block Try Block 0 1 0 0
consider the code & choose the correct
output:
class Threads2 implements Runnable {
Given:
public class TestSeven extends Thread {
private static int x;
public synchronized void doThings() {
int current = x;
current++;
x = current; Declaring the
} Synchronizin doThings()
public void run() { g the run() method as
doThings(); method would static would
Exception_ha } make the make the An exception
ndling_NewQ } Compilation class class is thrown at
B Which statement is true? MCQ fails. thread-safe. thread-safe. runtime. 0 0 1 0
class X2
{
public X2 x;
public static void main(String [] args)
{
X2 x2 = new X2(); /* Line 6 */
X2 x3 = new X2(); /* Line 7 */
x2.x = x3;
x3.x = x2;
x2 = new X2();
x3 = x2; /* Line 11 */
}
}
Garbage_Coll
ection_NewQ after line 11 runs, how many objects are
B eligible for garbage collection? MCQ 1 2 3 0 0 1 0
Given :
public class MainOne {
public static void main(String args[]) {
String str = "this is java";
System.out.println(removeChar(str,'s'));
}
Given:
class A {
final void meth() {
System.out.println("This is a final
method.");
}
}
class B extends A {
void meth() {
System.out.println("Illegal!");
}
}
class MyClass8{
public static void main(String[] args) {
A a = new A();
Inheritance_In a.meth();
terfaces_Abst B b= new B(); This is a final
ract b.meth(); method illegal Some
Classes_New } This is a final Some error Compilation error
QB }What would be the result? MCQ method illegal message error message 0 0 1 0
Which Man class properly represents the
relationship "Man has a best friend who is a
Inheritance_In Dog"?
terfaces_Abst A)class Man extends Dog { }
ract B)class Man implements Dog { }
Classes_New C)class Man { private BestFriend dog; }
QB D)class Man { private Dog bestFriend; } MCQ A B C D 0 0 0 1
What will be the output of the program?
class SuperClass
{
public Integer getLength()
{
return new Integer(4);
}
}
Given: abstract
interface DoMath class AllMath
{ implements
double getArea(int r); DoMath,
} interface MathPlus
interface MathPlus class AllMath AllMath { public class AllMath
Inheritance_In { extends implements double implements
terfaces_Abst double getVolume(int b, int h); DoMath MathPlus getArea(int MathPlus
ract } { double { double rad) { return { double
Classes_New /* Missing Statements ? */ getArea(int getVol(int x, rad * rad * getArea(int
QB Select the correct missing statements. MCQ r); } int y); } 3.14; } } rad); } 0 0 1 0
Consider the following code and choose the
correct option:
class A{
void display(byte a, byte b){
Inheritance_In System.out.println("sum of byte"+(a+b)); }
terfaces_Abst void display(int a, int b){
ract System.out.println("sum of int"+(a+b)); } Compiles but
Classes_New public static void main(String[] args) { Compilation error at
QB new A().display(3, 4); }} MCQ sum of byte 7 error sum of int7 runtime 0 0 1 0
Consider the following code and choose the
correct option:
interface Output{
void display();
void show();
}
Inheritance_In class Screen implements Output{
terfaces_Abst void display()
ract { System.out.println("display"); }public static Compiles but
Classes_New void main(String[] args) { Compilation error at run Runs but no
QB new Screen().display();}} MCQ display error time output 0 1 0 0
class Animal {
void makeNoise() {System.out.println("generic
noise"); }
}
class Dog extends Animal {
void makeNoise()
{System.out.println("bark"); }
void playDead() { System.out.println("roll
over"); }
}
class CastTest2 {
public static void main(String [] args) {
Dog a = (Dog) new Animal();
Inheritance_In a.makeNoise();
terfaces_Abst }
ract }
Classes_New consider the code above & select the proper
QB output from the options. MCQ run time error generic noise bark compile error 1 0 0 0
class Money {
private String country = "Canada";
Inheritance_In public String getC() { return country; } }
terfaces_Abst class Yen extends Money {
ract public String getC() { return super.country; } Compiles but
Classes_New public static void main(String[] args) { Compilation error at run
QB System.out.print(new Yen().getC() ); } } MCQ Canada error time null 0 1 0 0
we must use we must use
always always
Inheritance_In extends and implements
terfaces_Abst later we must and later we we can use in extends and
ract When we use both implements & extends use must use any order its implements
Classes_New keywords in a single java program then what implements extends not at all a can't be used
QB is the order of keywords to follow? MCQ keyword. keyword. problem together 1 0 0 0
Given:
interface A { public void methodA(); }
interface B { public void methodB(); }
interface C extends A,B{ public void
methodC(); } //Line 3 If you define If you define
class D implements B { D e = (D) D e = (D)
public void methodB() { } //Line 5 (new E()), (new E()),
} then then
class E extends D implements C { //Line 7 e.methodB() e.methodB()
Inheritance_In public void methodA() { } invokes the invokes the
terfaces_Abst public void methodB() { } //Line 9 Compilation version of Compilation version of
ract public void methodC() { } fails, due to methodB() fails, due to methodB()
Classes_New } an error in defined at line an error in defined at line
QB What would be the result? MCQ line 3 9 line 7 5 0 1 0 0
It must be It must be
Inheritance_In used in the used in the
terfaces_Abst It can only be last first
ract used in the Only one statement of statement of
Classes_New Which of the following statements is true parent's child class the the
QB regarding the super() method? MCQ constructor can use it constructor. constructor. 0 0 0 1
Given:
11. class ClassA {}
12. class ClassB extends ClassA {}
13. class ClassC extends ClassA {}
and:
21. ClassA p0 = new ClassA();
Inheritance_In 22. ClassB p1 = new ClassB();
terfaces_Abst 23. ClassC p2 = new ClassC();
ract 24. ClassA p3 = new ClassB();
Classes_New 25. ClassA p4 = new ClassC(); p1 =
QB Which TWO are valid? (Choose two.) MCA p0 = p1; p2 = p4; (ClassB)p3; p1 = p2; 0.5 0 0.5 0
class Animal {
void makeNoise() {System.out.println("generic
noise"); }
}
class Dog extends Animal {
void makeNoise()
{System.out.println("bark"); }
void playDead() { System.out.println("roll
over"); }
}
class CastTest2 {
public static void main(String [] args) {
Animal a = new Dog();
Inheritance_In a.makeNoise();
terfaces_Abst }
ract }
Classes_New consider the code above & select the proper
QB output from the options. MCQ run time error generic noise bark compile error 0 0 1 0
What will be the result when you try to
compile and run the following code?
class Base1 {
Base1() {
int i = 100;
System.out.println(i);
}
}
Given:
class Pizza {
java.util.ArrayList toppings;
public final void addTopping(String topping) {
toppings.add(topping);
}
}
public class PepperoniPizza extends Pizza {
public void addTopping(String topping) {
System.out.println("Cannot add Toppings");
}
public static void main(String[] args) {
Inheritance_In Pizza pizza = new PepperoniPizza();
terfaces_Abst pizza.addTopping("Mushrooms"); A
ract } The code NullPointerEx
Classes_New } Compilation Cannot add runs with no ception is
QB What is the result? MCQ fails. Toppings output. thrown 1 0 0 0
Consider the following code and choose the
correct option:
interface console{
int line=10;
void print();}
Inheritance_In class a implements console{
terfaces_Abst void print(){
ract System.out.print("A");} Compiles but
Classes_New public static void main(String ar[]){ Compilation error at run Runs but no
QB new a().print();}} MCQ A error time output 0 1 0 0
Inheritance_In
terfaces_Abst
ract private final public static
Classes_New Which of these field declarations are legal in public int final static int static int int answer =
QB an interface? (Choose all applicable) MCA answer = 42; answer = 42; answer = 42; int answer; 42; 0.25 0.25 0.25 0 0.25
Given :
No—there No—but a
Day d; must always object of Yes—an
Inheritance_In BirthDay bd = new BirthDay("Raj", 25); be an exact parent type object can be Yes—any
terfaces_Abst d = bd; // Line X match can be assigned to a object can be
ract between the assigned to a reference assigned to
Classes_New Where Birthday is a subclass of Day. State variable and variable of variable of the any reference
QB whether the code given at Line X is correct: MCQ the object child type. parent type. variable. 0 0 1 0
If both a
subclass and If neither Calling
its super() nor super() as the
superclass this() is first
do not have declared as statement in
A super() or any declared the first If super() is the body of a
this() call constructors, statement in the first constructor of
must always the implicit the body of a statement in a subclass
be provided default constructor, the body of a will always
Inheritance_In explicitly as constructor of this() will constructor, work, since
terfaces_Abst the first the subclass implicitly be this() can be all
ract statement in will call inserted as declared as superclasses
Classes_New the body of a super() when the first the second have a default
QB Select the correct statement: MCQ constructor. run statement. statement constructor. 0 1 0 0 0
Inheritance_In
terfaces_Abst public final final data
ract data type static final type
Classes_New Choose the correct declaration of variable in varaibale=inti static data data type variablename
QB an interface: MCQ alization; type variable; varaiblename; =intialization; 1 0 0 0
interface Vehicle{
void drive();
}
final class TwoWheeler implements Vehicle{
int wheels = 2;
public void drive(){
System.out.println("Bicycle");
}
}
class ThreeWheeler extends TwoWheeler{
public void drive(){
System.out.println("Auto");
}}
class Test{
public static void main(String[] args){
Inheritance_In ThreeWheeler obj = new ThreeWheeler();
terfaces_Abst obj.drive();
ract }}
Classes_New consider the code above & select the proper
QB output from the options. MCQ Auto Bicycle Auto compile error runtime error 0 0 1 0
Consider the following code and choose the
correct option:
interface employee{
void saldetails();
void perdetails();
}
abstract class perEmp implements employee{
public void perdetails(){
Inheritance_In System.out.println("per details"); }}
terfaces_Abst class Programmer extends perEmp{
ract public static void main(String[] args) {
Classes_New perEmp emp=new Programmer(); sal details compilation per details
QB emp.saldetails(); }} MCQ sal details per details error sal details 0 0 1 0
Inheritance_In
terfaces_Abst
ract
Classes_New All data members in an interface are by abstract and public and public ,static default and
QB default MCQ final abstract and final abstract 0 0 1 0
Consider the following code and choose the
correct option:
interface console{
int line;
void print();}
Inheritance_In class a implements console{
terfaces_Abst public void print(){
ract System.out.print("A");} Compiles but
Classes_New public static void main(String ar[]){ Compilation error at run Runs but no
QB new a().print();}} MCQ A error time output 0 1 0 0
An abstract
class is one
An abstract which
class is one contains An abstract
Inheritance_In which some defined class is one
terfaces_Abst contains methods and which
ract general some contains only Abstract
Classes_New Which of the following is correct for an purpose undefined static class can be
QB abstract class. (Choose TWO) MCA methods methods methods declared final 0.5 0.5 0 0
abstract
class class Vehicle
Inheritance_In abstract abstract { abstract abstract
terfaces_Abst class Vehicle Vehicle Vehicle void display(); class Vehicle
ract { abstract { abstract { abstract { System.out. { abstract
Classes_New Which of the following defines a legal abstract void void void println("Car"); void
QB class? MCQ display(); } display(); } display(); } }} display(); } 0 0 0 0 1
Consider the code below & select the correct
ouput from the options:
class Mountain{
int height;
protected Mountain(int x) { height=x; }
public int getH(){return height;}}
class SomeException {
}
class A {
public void doSomething() { }
} Compilation Compilation
Inheritance_In of class A will of class B will
terfaces_Abst class B extends A { Compilation Compilation fail. fail.
ract public void doSomething() throws of both of both Compilation Compilation
Classes_New SomeException { } classes A & classes will of class B will of class A will
QB } MCQ B will fail succeed succeed succeed 0 0 0 1
No—if a
class
implements
several Yes— either
interfaces, of the two
each variables can
Inheritance_In constant No—a class be accessed Yes—since
terfaces_Abst must be may not through : the definitions
ract Is it possible if a class definition implements defined in implement interfaceNam are the same
Classes_New two interfaces, each of which has the same only one more than e.variableNa it will not
QB definition for the constant? MCQ interface one interface me matter 0 0 1 0
The
An overriding parameter list
method can of an
declare that it overriding
throws method can
checked be a subset The overriding
Inheritance_In Private A subclass exceptions of the method must
terfaces_Abst methods can override that are not parameter list have different
ract cannot be any method thrown by the of the method return type as
Classes_New overridden in in a method it is that it is the overridden
QB Select the correct statement: MCQ subclasses superclass overriding overriding method 1 0 0 0 0
Consider the following code and choose the
correct option:
class A{
void display(){ System.out.println("Hello
A"); }}
class B extends A{
void display(){
System.out.println("Hello B"); }}
Inheritance_In public class Test {
terfaces_Abst public static void main(String[] args) {
ract A a=new B(); Compiles but
Classes_New B b= a; Compilation error at
QB b.display(); }} MCQ Hello A error Hello B runtime 0 1 0 0
Helps the
compiler to
find the
source file
that
corresponds
to a class,
when it does Helps
Which of the following option gives one not find a Helps JVM to Javadoc to
Introduction_t possible use of the statement 'the name of To maintain class file find and build the Java
o_Java_and_ the public class should match with its file the uniform while execute the Documentatio
SDE_NewQB name'? MCQ standard compiling classes n easily 0 1 0 0
Holds the Holds the
location of Holds the location of
Core Java location of User Defined
Introduction_t Class Library Java classes, Holds the
o_Java_and_ Which of the following statement gives the (Bootstrap Extension packages location of
SDE_NewQB use of CLASSPATH? MCQ classes) Library and JARs Java Software 0 0 1 0
Class and
Interfaces in
the sub
packages will
Sub be
Packages Packages packages automatically
can contain can contain should be available to
both Classes non-java declared as the outer
Packages and elements private in packages
Introduction_t can contain Interfaces such as order to deny without using
o_Java_and_ Which of the following are true about only Java (Compiled images, xml importing import
SDE_NewQB packages? (Choose 2) MCA Source files Classes) files etc. them statement. 0 0.5 0.5 0 0
Introduction_t Which of the following options give the valid
o_Java_and_ argument types for main() method? (Choose
SDE_NewQB 2) MCA String [][]args String args String[] args[] String[] args String args[] 0 0 0 0.5 0.5
Introduction_t dollorpack. [email protected] .package.sub
o_Java_and_ Which of the following options give the valid $pack.$ _score.pack. [email protected] package.inne
SDE_NewQB package names? (Choose 3) MCA $pack $$.$$.$$ __pack erp@ckage rpackage 0.333333 0.333333 0.333333 0 0
Object class
provides the
Object class method for
has the core Set Object class
Object class methods for implementati implements
Introduction_t Object class cannot be thread on in Serializable
o_Java_and_ Which of the following statements are true is an abstract instantiated synchronizati Collection interface
SDE_NewQB regarding java.lang.Object class? (Choose 2) MCA class directly on framework internally 0 0 0.5 0.5 0
Java
Introduction_t Java Runtime Database
o_Java_and_ The term 'Java Platform' refers to Java Compiler Environment Connectivity Java
SDE_NewQB ________________. MCQ (Javac) (JRE) (JDBC) Debugger 0 1 0 0
registerDriver(
) method and
JDBC_NewQ Which of the following methods are needed for registerDriver( Class.forNam Class.forNam getConnectio
B loading a database driver in JDBC? MCQ ) method e() e() n 0 0 1 0
Using the
static method
registerDriver(
) method
Using which is Either
forName() available in forName() or
JDBC_NewQ which is a DriverManage registerDriver( None of the
B how to register driver class in the memory? MCQ static method r Class. ) given options 0 0 1 0
while (rs.next()) {
String name = rs.getString("name");
System.out.println(name);
}
rs.close();
// somecode
JDBC_NewQ } What should be imported related to java.sql.Resul java.sql.Driver java.sql.Conn
B ResultSet? MCQ tSet java.sql.Driver Manager ection 1 0 0 0
It returns int
value as
mentioned
below: > 0 if
many
columns
Contain Null
Value < 0 if
It returns true no column
when last contains Null
There is no read column Value = 0 if
such method contain SQL one column
JDBC_NewQ What is the use of wasNull() in ResultSet in ResultSet NULL else contains Null none of the
B interface? MCQ interface returns false value listed options 0 1 0 0
Given :
public class MoreEndings {
public static void main(String[] args) throws
Exception {
Class driverClass =
Class.forName("sun.jdbc.odbc.JdbcOdbcDrive
r");
DriverManager.registerDriver((Driver)
driverClass.newInstance());
// Some code java.sql.Driver
JDBC_NewQ } Inorder to compile & execute this code, what java.sql.Driver java.sql.Data
B should we import? MCQ java.sql.Driver java.sql.Driver Manager Source 0 0 1 0
Which of the following method can be used to
JDBC_NewQ execute to execute all type of queries i.e. executeAllSQ executeQuer executeUpdat
B either Selection or Updation SQL Queries? MCQ executeAll() L() execute() y() e() 0 0 1 0 0
JDBC_NewQ Which method will return boolean when we try executeUpdat executeQuer
B to execute SQL Query from a JDBC program? MCQ e() executeSQL() execute() y() 0 0 1 0
Cosider the following code & select the
correct output.
String sql ="select rollno, name from
student";
PreparedStatement
pst=cn.prepareStatement(sql);
System.out.println(pst.toString());
ResultSet rs=pst.executeQuery(); Compiles but
JDBC_NewQ while(rs.next()){ will show only Compilation error at run
B System.out.println(rs.getString(3)); } MCQ name error will show city time 0 0 0 1
class CreateFile{
public static void main(String[] args) {
try {
File directory = new File("c"); //Line 13
File file = new File(directory,"myFile");
if(!file.exists()) {
file.createNewFile(); //Line 16
}}
catch(IOException e) { Line 13
e.printStackTrace } creates a
}}} Line 13 directory
If the current direcory does not consists of Line 16 is An exception creates a File named “c” in
JDBC_NewQ directory "c", Which statements are true ? never is thrown at object named the file
B (Choose TWO) MCA executed runtime “c” system. 0 0.5 0.5 0
1) Driver 2)
Connection 3)
ResultSet 4) 1) Driver 2)
ResultSetMet Connection 3)
aData 5) ResultSet 4)
Statement 6) ResultSetMet
DriverManage aData 5)
r 7) Statement 6)
PreparedStat PreparedStat
1) Driver 2) ement 8) ement 7)
Connection 3) Callablestate Callablestate
ResultSet 4) ment 9) ment 8)
JDBC_NewQ Which of the following options contains only DriverManage DataBaseMet DataBaseMet All of the
B JDBC interfaces? MCQ r 5) Class aData aData given options 0 0 1 0
Rodent rod;
Rat rat = new Rat();
Mouse mos = new Mouse();
Keywords_var PocketMouse pkt = new PocketMouse();
iables_operat
ors_datatype Which one of the following will cause a
s_NewQB compiler error? MCQ rod = mos pkt = rat pkt = null rod = rat 0 1 0 0
Consider the code below & select the correct
ouput from the options:
class Test{
public static void main(String[] args) {
parse("Four"); } A
static void parse(String s){ A NumberForm
try { ParseExcepti atException
Keywords_var double d=Double.parseDouble(s); on is thrown is thrown by
iables_operat }catch(NumberFormatException nfe){ by the parse the parse
ors_datatype d=0.0; }finally{ Compilation method at method at
s_NewQB System.out.println(d); } }} MCQ error runtime runtime 0 1 0 0
accessModifier returnType
methodName( parameterList ) It can be
{ omitted, but if
Java statements not omitted
there are The access It can be
return returnValue; several modifier must omitted, but if
Keywords_var } It must choices, agree with not omitted it
iables_operat always be including the type of must be
ors_datatype private or private and the return private or
s_NewQB What is true for the accessModifier? MCQ public public value public 0 1 0 0
class Accounts
Keywords_var {
iables_operat public double calculateBonus(){//method's
ors_datatype code} Simple
s_NewQB } MCQ Aggregation Association Dependency Composition 0 0 1 0
Given classes A, B, and C, where B extends
Keywords_var A, and C extends B, and where all classes
iables_operat implement the instance method void doIt().
ors_datatype How can the doIt() method in A be It is not his.super.doIt ((A)
s_NewQB called from an instance method in C? MCQ possible super.doIt() () this).doIt(); A.this.doIt() 1 0 0 0 0
Keywords_var
iables_operat int [] a =
ors_datatype Which of the following will declare an array Array a = {23,22,21,20, int a [] = new
s_NewQB and initialize it with five numbers? MCQ new Array(5); 19}; int[5]; int [5] array; 0 1 0 0
Keywords_var
iables_operat
ors_datatype Which of the following are correct variable
s_NewQB names? (Choose TWO) MCA int #ss; int 1ah; int _; int $abc; 0 0 0.5 0.5
What is the output of the following:
int a = 0;
Keywords_var int b = 10;
iables_operat
ors_datatype a = --b ;
s_NewQB System.out.println("a: " + a + " b: " + b ); MCQ a: 9 b:11 a: 10 b: 9 a: 9 b:9 a: 0 b:9 0 0 1 0
As per the following code fragment, what is
the value of a?
Keywords_var String s;
iables_operat int a;
ors_datatype s = "Foolish boy.";
s_NewQB a = s.indexOf("fool"); MCQ -1 4 random value 1 0 0 0
Consider the following code snippet:
Keywords_var int i = 10;
iables_operat int n = i++%5;
ors_datatype What are the values of i and n after the code
s_NewQB is executed? MCQ 10, 1 11, 1 10, 0 11 , 0 0 0 0 1
Consider the following code and choose the
correct output:
int value = 0;
Keywords_var int count = 1;
iables_operat value = count++ ;
ors_datatype System.out.println("value: "+ value + " count: value: 0 value: 0 value: 1 value: 1
s_NewQB " + count); MCQ count: 0 count: 1 count: 1 count: 2 0 0 0 1
Consider the following code and select the
correct output:
class Test{
interface Y{
void display(); }
public static void main(String[] args) {
Keywords_var new Y(){
iables_operat public void display(){ Compiles but Compiles but
ors_datatype System.out.println("Hello World"); } }; Compilation error at run run without
s_NewQB }} MCQ Hello World error time output 0 0 0 1
What is the output of the following program?
public class demo {
public static void main(String[] args) {
int arr[5];
for (int i = 0; i < arr.length; i++) {
arr[i] = arr[i] + 10;
}
for (int j = 0; j < arr.length; j++)
Keywords_var System.out.println(arr[j]); A sequence
iables_operat A sequence of Garbage
ors_datatype } of five 10's Values are compile time Compiles but
s_NewQB } MCQ are printed printed Error no output 0 0 1 0
Threads_New Which of the following methods registers a
QB thread in a thread scheduler? MCQ run(); construct(); start(); register(); 0 0 1 0
class PingPong2 {
synchronized void hit(long n) {
for(int i = 1; i < 3; i++)
System.out.print(n + "-" + i + " ");
}
}
public class Tester implements Runnable {
static PingPong2 pp2 = new PingPong2();
public static void main(String[] args) {
new Thread(new Tester()).start();
new Thread(new Tester()).start();
}
public void run()
{ pp2.hit(Thread.currentThread().getId()); } The output The output The output The output
Threads_New } could be 5-1 could be 6-1 could be 6-1 could be 6-1
QB Which statement is true? MCQ 6-1 6-2 5-2 6-2 5-1 5-2 5-2 6-2 5-1 6-2 5-1 7-1 0 1 0 0
Given:
public class Threads4 {
public static void main (String[] args) {
new Threads4().go();
}
public void go() {
Runnable r = new Runnable() {
public void run() {
System.out.print("run");
}
};
Thread t = new Thread(r);
t.start(); The code
t.start(); The code executes
} An exception executes normally, but
Threads_New } Compilation is thrown at normally and nothing is
QB What is the result? MCQ fails. runtime. prints "run". printed. 0 1 0 0
class Thread2 {
public static void main(String[] args) {
new Thread2().go(); }
public void go(){
Runnable rn=new Runnable(){
public void run(){
System.out.println("Good Day.."); } };
Thread t=new Thread(rn); The code
t.start(); executes
}} An exception normally and
Threads_New what should be the correct output for the code Compilation is thrown at prints "Good prints Good
QB written above? MCQ fails. runtime. Day.." Day.. Twice 0 0 1 0
public class MyRunnable implements
Runnable
{
public void run()
{
// some code here
} new new
} Runnable(My new new Thread(new
Threads_New which of these will create and start this Runnable).sta Thread(MyRu MyRunnable() MyRunnable()
QB thread? MCQ rt(); nnable).run(); .start(); ).start(); 0 0 0 1
Consider the following code and choose the
correct option:
class Nthread extends Thread{
public void run(){
System.out.print("Hi");} Will create
public static void main(String args[]){ two child
Nthread th1=new Nthread(); threads and will not create
Threads_New Nthread th2=new Nthread(); display Hi compilation any child will display Hi
QB } MCQ twice error thread once 0 0 1 0
Assume the following method is properly
synchronized and called from a thread A on
an object B:
if ( ring.startsWith("One") &&
find.startsWith("One") ) One ring to One ring to One ring to
strings_string System.out.println( ring+find ); rule them all, rule them all, rule them all,
_buffer_NewQ else One ring to One ring to \n One ring to Different
B System.out.println( "Different Starts" ); MCQ find them. find them. find them. Starts 1 0 0 0
The code will
Consider the following code and choose the fail to compile
correct option: because the
class MyClass { expression
String str1="str1"; str3.concat(st
String str2 ="str2"; r1) will not
String str3="str3"; result in a
str1.concat(str2); valid The program The program The program
strings_string System.out.println(str3.concat(str1)); argument for will print The program will print will print
_buffer_NewQ } the println() str3str1str2,w will print str3str1,when str3str2,when
B } MCQ method hen run str3,when run run run 0 0 0 1 0
Given:
public class Theory {
public static void main(String[] args) {
String s1 = "abc";
String s2 = s1;
s1 += "d";
System.out.println(s1 + " " + s2 + " " +
(s1==s2));
EqTest(){
String s="Java";
String s2="java";
// Line X
{
System.out.println("Equal");
}else
{
System.out.println("Not equal");
strings_string }
_buffer_NewQ } if(s.equals(s2 if(s.equalsIgn if(s.noCaseM if(s.equalIgnor
B } MCQ if(s==s2) )) oreCase(s2)) atch(s2)) eCase(s2)) 0 0 1 0 0
import java.io.*;
public class MyClass implements Serializable
{
private int a;
public int getA() { return a; }
publicMyClass(int a){this.a=a; }
private void writeObject( ObjectOutputStream
s)
throws IOException {
// insert code here
}
}
import java.io.*;
public class MyClass implements Serializable
{
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
public class MoreEndings {
public static void main(String[] args) {
try {
FileInputStream fis = new
FileInputStream("seq.txt");
InputStreamReader isr = new
InputStreamReader(fis);
int i = isr.read();
while (i != -1) {
System.out.print((char)i + "|");
i = isr.read();
}
} catch (FileNotFoundException fnf) {
System.out.println("File not found");
} catch (EOFException eofe) {
System.out.println("End of stream");
} catch (IOException ioe) {
System.out.println("Input error");
} The program
} will not
} compile The program
Assume that the file "seq.txt" exists in the because a The program The program will compile,
current directory, has the required certain will compile will compile print H|e|l|l|o|,
access permissions, and contains the string unchecked and print H|e| and print H|e| and then
IO_Operation "Hello". exception is l|l|o|Input l|l|o|End of terminate
s_NewQB Which statement about the program is true? MCQ not caught. error. stream. normally. 0 0 0 1
Consider the following code and choose the
correct option:
public class Test{ Skip the first
public static void main(String[] args) throws seven
IOException { characters
File file = new File("d:/temp.txt"); and then
FileReader reader=new FileReader(file); starts reading
reader.skip(7); int ch; file and Compiles and Compiles but
IO_Operation while((ch=reader.read())!=-1){ display it on Compilation runs without error at
s_NewQB System.out.print((char)ch); } }} MCQ console error output runtime 1 0 0 0
The file is
modified from
A file is readable but not writable on the file A being
system of the host platform. What will SecurityExce The boolean The boolean unwritable to
IO_Operation be the result of calling the method canWrite() ption is value false is value true is being none of the
s_NewQB on a File object representing this file? MCQ thrown returned returned writable. listed options 0 1 0 0 0
void add(int void add(int void add(int
Introduction_t x,int y) char char add(float x,int y) x,int y) void
o_OOPS_Ne Which of following set of functions are add(int x,int x) char char add(char sum(double
wQB example of method overloading MCQ y) add(float y) x,char y) x,double y) 0 0 1 0
Efficient avoiding
Introduction_t utilization of Code method name
o_OOPS_Ne What is the advantage of runtime memory at flexibility at confusion at
wQB polymorphism? MCQ runtime Code reuse runtime runtime 0 0 1 0
Introduction_t
o_OOPS_Ne Which of the following is an example of IS A Microprocess
wQB relationship? MCQ Ford - Car or - Computer Tea -Cup Driver -Car 1 0 0 0
Introduction_t
o_OOPS_Ne Which of the following is not a valid relation
wQB between classes? MCQ Inheritance Segmentation Instantiation Composition 0 1 0 0
Introduction_t
o_OOPS_Ne Which of the following is not an attribute of
wQB object? MCQ State Behaviour Inheritance Identity 0 0 0 1