Monday, April 13, 2009

100 questions in java

scjp questions


What is the output of this program
Q 1 class BoxAndWiden {
static void go(Object o) {

Integer i2 = (Integer) o;
System.out.println(i2);

}
public static void main(String [] args) {


go(1000);

}
}

1 compile time error
2 Runtime Error
3 1000
4 No output
3

Q 2
public class CheckIt{
int i;
CheckIt(){
i+=10;
}
public static void main(String[] args){
CheckIt t = new CheckIt();
System.out.print("value 1 = " +t.i);
CheckIt t1 = new CheckIt();
System.out.print(" value 2 = " +t1.i);
}
}

1 compile time error
2 Runtime Error
3 10 , 10
4 10 , 20
3


Q 3 what is the ouput

public class Demo1 {
String title;
int value;
public Demo1() {
title += " Java ";
}
public Demo1(int value) {
this.value = value;
title = "World ";
title= title.concat("Inside");
}
void Demo1(){
System.out.println("Running ");
}
public static void main(String a[]){
Demo1 c = new Demo1(5);
System.out.println(c.title);
}
}

1 compile time error
2 Runtime Error
3 Java
4 World
5 World Inside
6 None of these
5





Q 4 what is the output

public class Hello {
String title;
int value;
public Hello() {
title += " Java ";
}
public Hello(int value) {
this.value = value;
title = "World ";
title.concat("Inside");
}
void Hello(){
System.out.println("Running ");

}

public static void main(String a[]){
Hello c = new Hello(5);
System.out.println(c.title);
}
}



1 compile time error
2 Runtime Error
3 World
4 Java
5 None of these
3






Q 5 what is the output ?

public class PrintIt{
public static void main(String[] args){
int a;
PrintIt t = new PrintIt();
for(int j=0; j < 2 ; j++){
for(int i=0; i <4 ; i++){
a = j;

}

System.out.println(i);

}
}
}




1 compile time error
2 Runtime Error
3 prints 0 ,1 ,2,3
4 pirnts 0,1,2,3,4
5 None of these
1



Q 6 what is the output
public class TestArrayAObject{
int arr[] = new int[8];
public static void main(String[] args){
TestArrayAObject t = new TestArrayAObject();
System.out.println(t.arr[7]);
}
}



1 -0
2 compile time error
3 Runtime Exception
4 -1
5 None of these
1


Q 7 what is the output –

public class TestCAses {
public static void main(String[] args){
char c = '\u0044';
switch(c) {
default:
System.out.println("Default");
case 'A':
System.out.println("A");
case 'C':
System.out.println("C");
case 'B':
System.out.println("B");
}
}
}




1 compile time error
2 Runtime Error
3 default C A B
4 default B A C
5 default A C B
6 None of these
5


Q -8 what is the output

class Vararg { // 1
static void method1(long... a)//2
{ System.out.println("long type "); }//3
static void method1(int a,long... b)//4
{ System.out.println("int and long type "); //5
}

static void method1(Integer... a)// 6
{ System.out.println("Integer type "); }//7
public static void main(String [] args) {//8
method1(5,5); // 9
}
}




1 compile time error in line 1
2 compile time error in line 3
3 compile time error in line 7
4 compile time error in line 9
5 Runtime Error
6 None of these
4



Q 9

class WidenAndBox {
static void go(Long x) { System.out.println("Wrapper Long type"); }
public static void main(String [] args) {
long b = 5;
go(b);
}
}

1 compile time error
2 Runtime Error
3 Wrapper Long type
4 None of these
3


Q 10

public class Boxing1 {
public static void main(String[] args) {
Integer i = null;
method(i);
}
static void method(Object o){
if(o==null)
System.out.println("dont put null");
}
}




1 compile time error
2 Runtime Error
3 don put null
4 none of these
3







Q 11


public class Boxing2 {
public static void main(String[] args) {
byte b = 10;
method(b);
}
static void method(int i){
System.out.println("Primitivae Type call");
}
static void method(Integer i){
System.out.println("Wrapper Type Call");
}
}

1 compile time error
2 Runtime Error
3 Primitivae Type call
4 Wrapper Type Call
5 None of these
3

Q 12


public class Boxing3 {
public static void main(String[] args) {
int i = 10;
method(i);
}
static void method(Long l){
System.out.println("Widening conversion");
}
}

1 compile time error
2 Runtime Error
3 Widening conversion
4 None of these
1




Q 13

public class Boxing4 {
public static void main(String[] args) {
Integer i = 10;
Integer j = 10;
System.out.print(i==j);// trure
System.out.print(i.equals(j));// true
System.out.print(i != j);// false

}
}

1 compile time error
2 Runtime Error
3 true false ,false
4 true , true , false
5 true , true , true
6 false , false , trure
7 None of these
4



Q 14
public class Boxing5 {
public static void main(String[] args) {
Integer i = 128;
Integer j = 128;
System.out.print(i==j);//s false
System.out.print(i.equals(j));// true
}
}




1 compile time error
2 Runtime Error
3
4 false true
5 None of these
4





Q 15

public class Boxing6 {
public static void main(String[] args) {
Boolean b1 = new Boolean(true);
Boolean b2 = new Boolean(true);
boolean b3 = true;
Boolean b4 = true;
System.out.println(b1==b2);//f
System.out.println(b1==b3);//t
System.out.println(b3 == b4);//t
System.out.println(b1 == b4);//f
}
}




1 compile time error
2 Runtime Error
3
4
5 false true true , false
6 None of these
5

Q 16
public class Boxing7 {
public static void main(String[] args) {
int i = 10;
method(i);
Integer m =12;
method(m);

}
static void method(long l){
System.out.println("long called");
}
static void method(Integer i){
System.out.println("Integer called");
}
}




1 compile time error
2 Runtime Error
3 long called , Integer called
4 Integer called , long called
5 None of these
3





Q 17

public class Boxing8 {
public static void main(String[] args) {
Integer i = 10;
int k = 10;
method(i,k);

}
static void method(int i,Integer k){
System.out.println("1 int,Integer called");
}
static void method(int i,int k){
System.out.println("int,int called");;
}
static void method(Integer i,Integer k){
System.out.println("Integer,Integer called");;
}
static void method(Integer i,int k){
System.out.println(" Integer,int called");;
}
}

1 compile time error
2 Runtime Error
3 Integer,Integer called
4 Integer,int called
5 None of these
6 int,Integer called
4



Q 18



public class Boxing9 {
public static void main(String[] args) {
int i = 10;
method(i);
}

static void method(Object o){
System.out.println("Object called");
}
static void method(Number n){
System.out.println("Number called");
}
}


1 compile time error
2 Runtime Error
3 Object called
4 Number called
5 None of these
4





Q 19

import java.util.*;
class CheckHashSet{
public static void main(String ar[])
{

HashSet hs = new HashSet();
hs.add("scjp"); // 1
hs.add("exam"); //2
HashSet s = new HashSet();
s=hs; //3
System.out.println(s);
}
}




1 compile time error in line 1
2 compile time error in line 2
3 compile time error in line 3
4 Runtime Error
5 None of these
3

Q 20

public class Boxing10 {
public static void main(String[] args) {
int i = 10;
int k = 20;
method(i,k);
}
static void method(Integer... i){
System.out.println("Integer varargs is called");
}
static void method(Integer i,Integer j){
System.out.println(" Integer,Integer is called");
}
static void method(int... i){
System.out.println("int varargs is called");
}
}




1 compile time error
2 Runtime Error
3 int varargs is called
4 Integer,Integer is called
5 Integer varargs is called
6 None of these
4





Q 21 what is the ouput

public class CollectioinOverloading{

public static void method(float f){
System.out.println("Float");
}

public static void method(double f){
System.out.println("Double");
}
public static void main(String a[]){
float f1 = 2.0f;
float f2 = 2.0f;
method(1.0);//double
method(1.0f);// flt
method(1.0f*2.0f);// F
method(1.0f*2.0);// double

method(f1*f2);//F


}
}




1 compile time error
2 Runtime Error
3 double , float ,float , double, float
4 double , float ,float , float , double
5 None of these
6 float ,float , float , double , float
3




Q 22

import java.util.*;

public class DiffObeInAnArray{
public static void main(String ar[])
{
Object [] myObjects = {
new Integer(12),
new Integer(5),
new Boolean(true)
};
Arrays.sort(myObjects);

for(int i=0; i System.out.print(myObjects[i].toString());
System.out.print(" ");
}
}}



1 compile time error
2 classCastException
3 NullpoinerExceptin
4 pirnt all values
5 None of these
2






Q 23
import java.util.*;
public class Example {
public static void main(String[] args) {


Set set = new LinkedHashSet();

set.add(new Integer(3));

set.add(new Integer(2));
set.add(new Integer(2));


System.out.println(set);
}
}


1 compile time error
2 Runtime Error
3 - 3,2
4 3,2 2
5 -2,3
6 2,2,3
7 None of these
3




Q 24

class FinalCheck1{
public static void main(String ar[]){

//System.out.println(i);


}

static byte m2(final int i){
return i ;
}

}


1 compile time error
2 Runtime Error
3
4
5 None of these
1






Q 25
import java.util.*;

public class LinkedListsorting {

public static Collection get() {
Collection sorted = new LinkedList();
sorted.add("B"); sorted.add("C"); sorted.add("A");
sorted.add("A");
return sorted;
}

public static void main(String[] args) {


for (Object x : get()) {
System.out.print(x + ", ");
}
}
}



1 compile time error
2 Runtime Error
3 B , C, A ,
4 C , C B A
5 None of these
3


Q 27

import java.util.*;
public class TestLInkedHashMap{
public static void main(String a[]){
Map s = new LinkedHashMap();
s.put("1","one");
s.put("3","three");
s.put("2","two");

System.out.println(s);
}
}




1 compile time error
2 Runtime Error
3 1 = one , 3 =thre , 2 =two
4
5 None of these
3





Q 28


public class Test23{
public static void main(String a[]){
String s1 = "Sun";
System.out.println(s1.substring(0,2));
}
}


1 compile time error
2 Runtime Error
3 Sun
4 Su
5 un
6 None of these
4


Q 29
public class Test14{
static String s ="Instance";

public static void method(String s){
s+="Add";
}
public static void main(String a[]){
Test14 t = new Test14();
s = "New Instance";
String s = "Local";
method(s);
System.out.println(s);// local
System.out.println(t.s);//new instance
}
}




1 compile time error
2 Runtime Error
3 Local
4 Local ,new Instance
5 None of these
4





Q 30


public class Test13{
public static void method(String s){
System.out.println("String Version");
}

public static void method(StringBuffer sb){
System.out.println("String Buffer Version");
}

public static void main(String a[]){
method(null);
}
}





1 compile time error
2 Runtime Error
3
4
5 None of these
1


Q 31



import java.util.*;
class TestTreeSet1{
public static void main(String a[]){
Set s = new TreeSet();
s.add(new Person(20));
s.add(new Person(10));
System.out.println(s);
}
}
class Person{
Person(int i){}
}

1 compile time error
2 Runtime Error
3
4
5 None of these
2



Q 32

public class WaitTest {
public static void main(String [] args) {
System.out.print("1 ");
synchronized(args){
System.out.print("2 ");
try {
args.wait();
}
catch(InterruptedException e){}
}
System.out.print("3 ");
} }





1 compile time error
2 Runtime Error
3 1 2 and waits forever
4 2 1 and waits forever
5 None of these
3




Q 33

class DobleRunInThread{

public static synchronized void main(String[] args) throws
InterruptedException {
Thread t = new Thread();
t.start();
System.out.print("X");
t.wait(10000);
System.out.print("Y");
}
}





1 compile time error
2 Runtime Error
3
4
5 None of these
2




Q 34
public class TwoThreads {
static Thread laurel, hardy;
public static void main(String[] args) {
laurel = new Thread() {
public void run() {
System.out.println("A");//
try {
hardy.sleep(1000);
} catch (Exception e) {
System.out.println("B");
}
System.out.println("C");//
}
};
hardy = new Thread() {
public void run() {
System.out.println("D");//
try {
laurel.wait();
} catch (Exception e) {
System.out.println("E");//
}
System.out.println("F");//
}
};
laurel.start();
hardy.start();
}
}





1 compile time error
2 Runtime Error
3 A D E F C
4
5 None of these
3

Q 35

public class Messager implements Runnable {
public static void main(String[] args) {
new Thread(new Messager("ONE ")).start();
new Thread(new Messager("TWO ")).start();
}
private String name;
public Messager(String name) { this.name = name; }
public void run() {
message(1);
message(2);
}
private synchronized void message(int n) {
System.out.print(name + "-" + n + " ");
}
}


1 compile time error
2 Runtime Error
3
4 ONE -1 , TWO-1 , ONE -2 , TWO -2
5 None of these
4




Q 36



class ThreadTest extends Thread
{
public void run()
{
for(int i=0;i<100;i++)
{
System.out.println(i);
}
}
public static void main(String[] args) throws InterruptedException
{
ThreadTest tt = new ThreadTest();

tt.start();
tt.interrupt();

System.out.println("INTRUPTED ");

}
}




1 compile time error
2 Runtime Error
3 PRINT 1 TO 99 AND INTRUPTED IN BETWEEN RANDOMELY
4
5 None of these
3

Q 37

public class Threads4 implements Runnable {
public void run() {
System.out.println(" This is the thread task ");
}
public void run (String s ) {
System.out.println(" this is " +s);
}
public static void main(String[] args) {
Threads4 t4 =new Threads4();
t4.run("Customer -");
Thread t1= new Thread(t4);
t1 .start();
}
}





1 compile time error
2 Runtime Error
3
4 this is customer , this is the thread task
5 None of these
4


Q 38
class Animal { public String noise()
{
return "peep";
}
}

class Dog extends Animal {
public String noise() { return "bark"; }
}

class Cat extends Animal {
public String noise() { return "meow"; }
}


public class OverridingTest{
public static void main(String a[]){

Animal animal = new Dog();
Cat cat = (Cat)animal;
System.out.println(cat.noise());
}
}





1 compile time error
2 Runtime Exception
3
4
5 None of these
2

Q 39
public class Threads3 implements Runnable {
public void run() {
System.out.print("executing ");
}
public static void main(String[] args) {
Thread t1 = new Thread(new Threads3());
t1.run();
t1.run();
t1.start();
}
}





1 compile time error
2 Runtime Error
3 executing , executing , executing
4
5 None of these




Q 40

public class Threads2 implements Runnable {

public void run() {
System.out.println("running .");
throw new RuntimeException("Problem");
}

public static void main(String[] args) {

Thread t = new Thread(new Threads2());
t.start();
System.out.println("closing ");
}
}


1 compile time error
2 Runtime Error
3 prints randomly
4
5 None of these
3






Q 41

class Thread1 implements Runnable
{
public void run()
{

synchronized(this){
for(int i=0;i<5;i++)
{

System.out.println("In Thread1 "+Thread.currentThread().getName() +" Is Executing");
}

try
{
notifyAll();
}
catch(Exception e)
{
System.out.println(e);
}

}

}
}


public class ThreadJoin
{
public static void main(String [] arg)
{
Thread1 t1=new Thread1();


Thread th1=new Thread(t1);
th1.setName("A");
Thread th2=new Thread(t1);
th2.setName("B");
th1.start();
th2.start();

synchronized(th1){
try{
th1.wait();
}catch(InterruptedException ex){
}
}

synchronized(th2){
try{
th2.wait();
}catch(InterruptedException ex){
}
}


System.out.println("last line in main");


}
}

1 compile time error
2 Runtime Error
3 A , A B B OR B , B A , A AND MAIN OR B B , AA AND WAITING
4
5 None of these
3

Q 42
class MyThread extends Thread {

MyThread() {
System.out.print(" MyThread CONSTRUCTOR ");
}

public void run() { System.out.print(" NO ARG RUN"); }

public void run(String s) { System.out.print(" RUN WITH STRING "); }
}

public class TestThreads {

public static void main (String [] args) {
Thread t = new MyThread() {
public void run()
{
System.out.print(" HELLO WORLD ");
}
};
t.start();
}
}


1 compile time error
2 Runtime Error
3 MY THREAD , CONSTRUCTOR , HELLO WORL
4
5 None of these
3




Q 43


public class TestOne {

public static void sleepCheck()
{
try{
Thread.sleep(1000);
}
catch(Exception e ){}
}

public static void main (String[] args) throws Exception {
System.out.println("sleeping 1 ");

Thread.sleep(4000);
System.out.println("sleeping 2");
}
}





1 compile time error
2 Runtime Error
3 sleeping 1 " sleep for 4 seconds and sleeping 2
4
5 None of these
3



Q 44
class TestLock implements Runnable
{
private int a;
public void run()
{
for(int i=0;i<3;i++)
up();
}
public synchronized void up()
{
a=a+1;
System.out.println("a is - "+a);
}
public static void main(String[] args)
{

TestLock ta=new TestLock();
TestLock tb=new TestLock();
TestLock tc=new TestLock();

Thread t=new Thread(ta);
Thread to=new Thread(ta);
Thread to1=new Thread(ta);

t.start();
to.start();
to1.start();
}
}

1 compile time error
2 Runtime Error
3 a is 1 to 9 ( is printed)
4
5 None of these
3



Q 45

class Top {

Top()

{
System.out.print("top ");
}

public Top(String s) { System.out.print("B");
}

}


public class Bottom2 extends Top {
public Bottom2(String s)
{
System.out.print("D");
}
public static void main(String [] args) {
new Bottom2("C");
}
}






1 compile time error
2 Runtime Error
3 top d
4
5 None of these
3

Q 46


class A {
public int Instances;
public A(int Instances) {
this.Instances = Instances;
} }

class B extends A {
protected B(int Instances) { super(Instances);}
}
public class C extends B {
private C(int Instances) {
super(Instances); }
public static void main(String[] args) {
C ext = new C(100);
System.out.print(ext.Instances);
}
}






1 compile time error
2 Runtime Error
3 100
4
5 None of these
3



Q 47

public class Test {
public static void main (String [] args) {
final Foo f = new Foo();
Thread t = new Thread(new Runnable() {
public void run() {
f.doWork();
}
});

Thread g = new Thread() {
public void run() {
f.doWork();
}
};
t.start();
g.start();
}
}
class Foo {
int x = 5;
public void doWork() {
if (x < 10) {
// nothing to do
try {
wait();
} catch(InterruptedException ex) { }
} else {
System.out.println("x is " + x++);
if (x >= 10) {
notify();
}
}
}
}

1 compile time error
2 IllegalMonitorExceptin
3
4
5 None of these
2



Q 48
class Key{
public static void go() {
System.out.println("go in key");
}
}
class Board extends Key {
public static void go() {
System.out.println("go in board");
}
}
public class StaticMethodInheritence{
public static void main(String ar[])
{
Key k= new Key();
Board b= new Board();
b= (Board)k;
k.go();
}
}





1 compile time error
2 ClassCastException
3
4
5 None of these
2




Q 49

public class Starter extends Thread
{
private int x= 2;
public static void main(String[] args) throws Exception
{
new Starter().makeItSo();
}
public Starter()
{

start();
}
public void makeItSo() throws Exception
{
try{
Thread.sleep(1000);
}catch(Exception ex){

}

x=x- 1;
System.out.println(x);
}
public void run()
{
x *= 3;
}
}





1 compile time error
2 Runtime Error
3 sleep for 1 second and print 5
4
5 None of these
3



Q 50
import java.util.*;
public class PrQu {
public static void main(String[] args) {
PriorityQueue pq1 = new PriorityQueue();
pq1.add("carrot");
pq1.add("apple");
pq.add("banana");

System.out.println(pq1.poll() + ":" + pq.peek());
}
}

1 compile time error
2 Runtime Error
3 apple : banana
4
5 None of these
4






Q 51
public class Hello {
String title;
int value;
public Hello() {
title += " World";
}

public Hello(int value) {

this.value = value;
title = "Hello";
new Hello();

}

public static void main(String ar[])
{
Hello h = new Hello();
System.out.println(" "+ h.title);
}
}





1 compile time error
2 Runtime Error
3 null world
4
5 None of these
3


Q





1 compile time error
2 Runtime Error
3
4
5 None of these




Q 52
class Animal { }
class Dog extends Animal {
void doDogStuff()
{
System.out.println("dogs stuff ");
}
}
public class DogTest {
public static void main(String [] args) {
Animal a = new Dog();
Dog d = (Dog) a;
d.doDogStuff();

((Dog)a).doDogStuff();
}
}



1 compile time error
2 Runtime Error
3 dogs stuff
4
5 None of these
3


Q 53

interface Bounceable{
void bounce();
void setBounceFactor(int bf);
}
abstract class Ball implements Bounceable {
public abstract void hello();
public static void go(){
System.out.println("static method in abst class ");

}
public void bounce() {
System.out.println("bounce in abstract class");
}
public void setBounceFactor(int bf) {
System.out.println("set boucne factor in abst class ");
}
}
public class SoccerBall extends Ball {
public void hello()
{

}

public void bounce() {
System.out.println("bounce in soccer class");
} // Define bounce behavior
public void setBounceFactor(int bf) {
System.out.println("set boucne factor in soccer class ");
}
public static void main(String ar[])
{
SoccerBall sb= new SoccerBall ();
sb.bounce();
Ball.go();
}
}


1 compile time error
2 Runtime Error
3 bounce in soccer class , static method in abst class
4
5 None of these
3

Q 54

class charAndInt {
public static void main(String [] args) {
char x ='m';
int y=x;
System.out.println("y is "+y);
System.out.println("y is "+(char)y);
char a= 'm';
long l=a;
System.out.println("l is "+l);
System.out.println("l is "+(char)l);
char e= 'o';
short s =(short)e;
System.out.println("e is "+e);
System.out.println("e is "+(char)e);
}
}


1 compile time error
2 Runtime Error
3 y is 109 ,m 109,m,,o,o
4
5 None of these
3

Q 55
enum Dogs {co, ha, sh}
public class Test {

public static void main(String [] args) {
Dogs myDog = Dogs.co;

switch (myDog) {
case sh: System.out.print("SH ");
case co: System.out.print("CO ");
case ha: System.out.print("HA ");
default: System.out.println("DO");

}
}

}







1 compile time error
2 Runtime Error
3 CO HA DO
4
5 None of these
3



Q 56
enum Color {red, green, blue}

class SwitchEnum {
public static void main(String [] args) {
Color c = Color.green;
switch(c) {

case red: System.out.print("red ");
case green: System.out.print("green ");
case blue: System.out.print("blue ");
default: System.out.println("done");
}
}
}





1 compile time error
2 Runtime Error
3
4 green blue done
5 None of these
4
Q 57

enum Size {
SMALL{
public String toString(){
return "Small Size";
}
} ,
Medium ,

LARGE{
public String toString(){
return "Large Size";
}
};

}
class SizeTest{
public static void main(String[] args) {
System.out.println(Size.SMALL.toString());
System.out.println(Size.Medium.toString());
System.out.println(Size.LARGE.toString());
}
}





1 compile time error
2 Runtime Error
3 small size , medium size, large size
4
5 None of these
3



Q 58





1 compile time error
2 Runtime Error
3
4
5 None of these

Q 59

enum Season {
WINTER,
SUMMER,
SPRING,
AUTUMN
}
class SeasonTest{
public static void main(String[] args) {
Season season1 = Season.WINTER;
Season season2 = Season.SUMMER;
Season season3 = Season.SPRING;
Season season4 = Season.AUTUMN;

System.out.println(season1.equals(season2));//f
System.out.println(season3.equals(season4));//f
System.out.println(season3.equals(season3));//t
}
}


1 compile time error
2 Runtime Error
3 false , false , true
4
5 None of these
3


Q 60
//
public class StaticVaribleNotUsedOutSide {
static {
int a = 5;

}
static int a=9;

public static void main(String[] args){

System.out.println(a);
}
}





1 compile time error
2 Runtime Error
3 - 9
4
5 None of these
3


Q 61
class A
{
static void staticMethod()
{
System.out.println("static me");
}
void nonStaticMethod()
{
System.out.println("non- static ");
A.staticMethod();
}
}
class MainClass
{
public static void main(String[] args)
{
new A().nonStaticMethod();
}
}




1 compile time error
2 Runtime Error
3 non static , static me
4
5 None of these
3



Q 62

public class InstanceInitializer
{ public static void main (String [] args) {
Sub subobj = new Sub ();
System.out.println ("super is "+ super.initvar);
Super s1 = new Sub();
System.out.println ("initvaribal is "+ s1.initvar);
}
}
class Super
{
public int initvar = 100;
Super () {
{
initvar=this.initvar;
}
System.out.println ("In Super's constructor. initvar value = " + initvar);
}
}
class Sub extends Super
{
public int initvar = 200;
Sub () {
super ();
System.out.println ("Done calling super() in Sub class");
}
}





1 compile time error
2 Runtime Error
3
4
5 None of these
1

Q 63
public class inheritex
{
int i=5;
}

class inheritex1 extends inheritex
{
int i=3;
public static void main(String args[])
{
inheritex1 ex=new inheritex1();
System.out.println(ex.i);
}
}


1 compile time error
2 Runtime Error
3 - 3
4
5 None of these
3


Q 64
enum Drinks {
COFFEE("hot", 10.0), TEA("hot", 5.0), JUICE("cold", 20.0), LASSI(8.0);
String state;
double price;

private Drinks(String s, double p) {
state = s;
price = p;
}
private Drinks(double p) {
price = p;
}
private Drinks(Double p) {
price = p;
}
public String toString() {
return "This Item is " + state + " and costs $" + price;
}
}
class EnumThree {
public static void main(String[] args) {
System.out.println(Drinks.LASSI);
System.out.println(Drinks.JUICE);
}
}


1 compile time error
2 Runtime Error
3
4 This Item is null and cost is $ 8.0, This Item is cold and cost is $ 20.0
5 None of these
4

Q 65

import java.util.*;
class GEnes{
public static void main(String[] args) {
List al = new ArrayList(); //line 1
al.add(12.2); //line 2
for (Object no:al) //line 3-
{System.out.println(no);}

}
}

1 compile time error
2 Runtime Error
3
4
5 None of these
1



Q 66

enum Drinks {
COFFEE("hot", 10.0), TEA("hot", 5.0), JUICE("cold", 20.0), LASSI(8.0);
String state;
double price;

private Drinks(String s, double p) {
state = s;
price = p;
}
private Drinks(double p) {
price = p;
}
private Drinks(Double p) {
price = p;
}
public String toString() {
return "This Item is " + state + " and costs $" + price;
}
}
class EnumThree {
public static void main(String[] args) {
System.out.println(Drinks.LASSI);
System.out.println(Drinks.JUICE);
}
}





1 compile time error
2 Runtime Error
3
4
5 None of these

Q 67
enum Position {
FIRST, SECOND, THIRD;
public static void main(String[] args) { //line 1
Position p = Position.THIRD; //line 2
switch(p) {
default :
System.out.println("Better luck defluat time");
break;
case FIRST : //line 4
System.out.println("Congrats, You are the FIRST winner");
//line 6
case SECOND :
System.out.println("Congrats, You are the second winner ");


}
}
}


1 compile time error
2 Runtime Error
3 Better luck defluat time"
4
5 None of these
3




Q 68

class Outer {
// class has static enum and static inner class


static enum OuterEnum { OUT, OUTTER} //line 1


static class Inner { //line 2
enum InnerEnum { IN, INNER} //line 3
}

public static void main(String [] args) {
System.out.println(Outer.OuterEnum.OUT + " " + Outer.Inner.InnerEnum.IN); //line 6
}
}

1 compile time error
2 Runtime Error
3 OUT ,IN
4
5 None of these

Q 69
class EnumEight {
enum Shape {
CIRCLE("zero"), RECTANGLE("four") ,SQUARE("four") ,TRIANGLE("three");
String sides;
private Shape(String s) {
sides = s;
}
public String toString() {
return sides;
}
}
public static void main(String [] args) {
System.out.println(Shape.CIRCLE + " " + Shape.RECTANGLE + " " + Shape.SQUARE + " " + Shape.TRIANGLE);
}

}


1 compile time error
2 Runtime Error
3 zero , four , four three
4
5 None of these
3




Q 70
enum Seasons {
WINTER,
SUMMER,
SPRING,
AUTUMN;
}
class SeasonsTest10{
public static void main(String[] args) {
Seasons season1 = Seasons.SUMMER;
Seasons season2 = Seasons.WINTER;
Seasons season3 = Seasons.SPRING;
Seasons season4 = Seasons.AUTUMN;

System.out.println(season1.compareTo(season2));//
System.out.println(season3.compareTo(season4));//

System.out.println(season4.compareTo(season3));
System.out.println(season2.compareTo(season1));
System.out.println(season3.compareTo(season3));
System.out.println(season1.compareTo(season4));
}
}


1 compile time error
2 Runtime Error
3 1 , -1 ,1 , -1 , 0 , - 2
4
5 None of these
3

Q 71

import java.util.*;
class TestGen
{
public static void main(String[] args)
{
//List list = new ArrayList();
List list = new ArrayList();
list.add(new BullDog ());
}
}
class Animal
{}
class Cat extends Animal{}
class Dog extends Animal{}
class BullDog extends Dog{}
class CowDog extends BullDog{}






1 compile time error
2 Runtime Error
3
4
5 None of these
1




Q 72



enum Direction {
SOUTH("eastern"),WEST("western"),EAST("northen"),

NORTH("southen"){
public String toString() { return "HELLO"; }
};

String side;
private Direction(String d) {
side = d;
}
public String toString() {
return "HI";
}

}
class EnumTwo {
public static void main(String[] args) {
System.out.println(Direction.NORTH + " " + Direction.WEST + " " + Direction.EAST + " " + Direction.SOUTH);
}
}





1 compile time error
2 Runtime Error
3
4 HELLO , HI , HI , HI
5 None of these

Q 73
import java.util.*;
class priQue{
public static void main(String ar[]){

PriorityQueue pq = new PriorityQueue();
pq.add("2");
pq.add("4");
pq.add("3");
pq.add("1");
pq.add("10");
System.out.println(pq);
PriorityQueue pq1 = new PriorityQueue();
pq1.add("2");
pq1.add("3");
pq1.add("5");
pq1.add("6");

pq1.add("4");
System.out.println(pq1);

}
}





1 compile time error
2 Runtime Error
3 ,10 ,3,4, 2,, 2 , 3 , 5 , 6 , 4
4
5 None of these




Q 74



enum Colors {
RED,
GREEN,
BLUE
}
class ColorsTest1{
public static void main(String[] args) {
System.out.println(Colors.GREEN.ordinal());//
System.out.println(Colors.BLUE.ordinal());//
System.out.println(Colors.RED.ordinal());//

}
}




1 compile time error
2 Runtime Error
3 1 , 2, 0
4
5 None of these

Q 75




class EnumD {
enum DIMENTION {
N("S"), S("E") ,E("N") ,W("W");

String name;
private DIMENTION(String s) {
name = s;
}
public String toString() {
return name;
}
}

public static void main(String [] args) {
System.out.println(DIMENTION.N + " " + DIMENTION.S);

}


}





1 compile time error
2 Runtime Error
3 S E
4
5 None of these
3




Q 76





1 compile time error
2 Runtime Error
3
4
5 None of these

Q 77

enum Device {
DEVEICE1,
DEVICE2,
DEVICE3
}
class DeviceTest{
public static void main(String[] args) {
Device anyDevice = new Device();

}
}





1 compile time error
2 Runtime Error
3
4
5 None of these
1




Q 78





1 compile time error
2 Runtime Error
3
4
5 None of these

Q 79





1 compile time error
2 Runtime Error
3
4
5 None of these




Q 80





1 compile time error
2 Runtime Error
3
4
5 None of these

Q 81





1 compile time error
2 Runtime Error
3
4
5 None of these




Q 82
class Test {
enum Taste {
SWEET { public String toString() { return "very sweet ";} },
HOT { public String toString() { return "very HOT";}},
SPICY { public String toString() { return "very spicy ";}}
}
static class Sample {
enum Taste {
BITTER { public String toString() { return "SWEET-static";}},
SWEET { public String toString() { return "HOT-static";} },
JUICY { public String toString() { return "SPICY-static ";} };
}
}
}
class EnumSix1 {
public static void main(String [] args) {
System.out.println(Test.Taste.SWEET + " " + Test.Sample.Taste.SWEET);
}
}





1 compile time error
2 Runtime Error
3 very sweet , hot static
4
5 None of these

Q 83
enum AccountType {
SAVING, FIXED, CURRENT,FIVEYEAR;


private AccountType() {
System.out.println("It is a account type");
}
}
class EnumOne {
public static void main(String[] args) {
System.out.println(AccountType.FIXED);
}
}





1 compile time error
2 Runtime Error
3 4 times It is a account type , FIXED
4
5 None of these
3




Q 84


class Test {
enum Taste {
SWEET { public String toString() { return "BITTER";} },
HOT { public String toString() { return "HOT";}},
SPICY { public String toString() { return "SWEET";}};
}
static class Sample {
enum Taste {
BITTER { public String toString() { return "SWEET";}},
SWEET { public String toString() { return "HOT";} },
JUICY { public String toString() { return "SPICY";} };
}
}
}
class EnumSix {
public static void main(String [] args) {
//insert the line here


System.out.println(Test.Taste.SWEET);
}
}





1 compile time error
2 Runtime Error
3
4 BITTER
5 None of these
4


Q 85
import java.util.*;
class CollectionTest{
public static void append(List list)
{
list.add(new Integer(1));
}
public static void main(String[] args) {
List intList = new ArrayList();
append(intList);
System.out.println(intList.toString());// will print 1
}
}


1 compile time error
2 Runtime Error
3 [1]
4
5 None of these
3


Q 86

import java.util.*;
class CollectionSearch{
public static void search(List list) {
list.clear();
list.add("b");
list.add("j");
list.add("a");
list.add("c");
list.add("c");
System.out.println(Collections.binarySearch(list, "c"));
}
public static void main(String[] args) {
List l;
search(l);
}}

1 compile time error
2 Runtime Error
3
4
5 None of these
1

Q 87




public class Boxer1{
Integer i;
int x;
public Boxer1(int y) {
x = i+y;
System.out.println(x);
}
public static void main(String[] args) {
new Boxer1(new Integer(4));
}
}


1 compile time error
2 Runtime Error
3
4
5 None of these
2




Q 88

class TestA {
public void start() { System.out.println("TestA"); }

}
class TestB extends TestA {
public void start() { System.out.println("TestB"); }

public static void main(String[] args) {
((TestA)new TestB()).start();
}

}


1 compile time error
2 Runtime Error
3 Test b
4
5 None of these
3


Q 89


public class Ball{
public enum Color { RED, GREEN, BLUE };
public void foo(){
for( Color c : Color.values() )
{
System.out.println(c);
}
}
public static void main(String ar[]){

Ball b= new Ball();
b.foo();
}
}




1 compile time error
2 Runtime Error
3 Red , greern blue
4
5 None of these
3



Q 90

class Outer
{
public Outer()
{
System.out.println("Outer is being instantiated");
}

class Inner{
public Inner()
{
System.out.println("Inner is being instantiated");
}
}
}


public class Other extends Outer.Inner{
public Other(Outer outerRef) {

outerRef.super();

}

public static void main(String... args)
{
Outer outerRef = new Outer();
Other otherRef = new Other(outerRef);
}
}





1 compile time error
2 Runtime Error
3 Outer is being ins, Inner is being instantiet
4
5 None of these
3



Q 91



class EnumTesting{

public enum Title {



MR("Mr."), MRS("Mrs."), MS("Ms.");
private final String title;

private Title(String t) { title = t; }

public String format(String last, String first) {
return title + " " + first + " " + last;
}
}



public static void main(String[] args) {
System.out.println(Title.MR.format("jon", "paul"));
}
}


1 compile time error
2 Runtime Error
3 mr. paul , jon
4
5 None of these
3



Q 92

enum IceCream {
VANILLA ("white"),
STAWBERRY ("pink"),
WALNUT ("brown"),
CHOCOLATE ("dark brown");

String color;

IceCream (String color) {
this.color = color;
}
}

public class enumTest04 {
public static void main (String[] args) {
IceCream vanilla = new IceCream ("white");
System.out.println ( vanilla );
}
}





1 compile time error
2 Runtime Error
3
4
5 None of these
1




Q 93



import java.io.*;

public class Test11 {
//implements Serializable {
public static void main(String[] args) {
Test11.Inner in = new Test11().new Inner();
try{
FileOutputStream fos = new FileOutputStream("Serialize.ser");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(in);
}catch(Exception e){
e.printStackTrace();
}
}
class Inner implements Serializable{
int i =10;
}
}




1 compile time error
2 Runtime Error
3
4
5 None of these
2




Q 94
class Foo {
Foo() {
System.out.print("foo ");
}

class Bar{
Bar()
{System.out.print("bar construoctor ");
}
public void go() {System.out.print(" Bar method go ");}
}
public static void main (String [] args) {
Foo f = new Foo();// foo
f.makeBar();
}
void makeBar() {
(new Bar() {}).go();
}
}




1 compile time error
2 Runtime Error
3 foo , bar construocor , Bar metoid go
4
5 None of these
3

Q 95
interface Foo {
int bar();
}
public class Beta2
{ class A implements Foo
{
public int bar() { return 1; }
}
public int fubar( Foo foo)
{ return foo.bar(); }

public void testFoo()
{

class A implements Foo
{
public int bar()
{ return 2; }
}
System.out.println( "testFoo method in Beta2->"+fubar( new A()));

}


public static void main( String[] argv)
{
new Beta2().testFoo();
}
}

1 compile time error
2 Runtime Error
3 testFoo method in Beta2->
4
5 None of these
3




Q 96


public class InnerClass {
public static void main(String args[]){
System.out.println(doStuff(1));
System.out.println(doStuff(2));
}

public static String doStuff(int y){
final int x=y;
class MyInner{

public String main1(){
return "here "+x;
}
}
MyInner inner = new MyInner();
return inner.main1();

}



}




1 compile time error
2 Runtime Error
3 here 1 ,here 2
4
5 None of these
3




Q 97

interface I {
public class A {// static, final works and wihout static also woriks
int a = 5;
protected void g() {

System.out.println("this is g method");
}
}
}
class Demo1 implements I {
public static void main(String[] args) {

I.A a1 = new I.A( );
a1.g( );
}
}





1 compile time error
2 Runtime Error
3
4 this is g method
5 None of these
4




Q 98

class Foo {
Foo() {System.out.println("foo- outer constroctor ");}
class Bar{
Bar()
{System.out.println("bar construocto r ");
}
public void go() {System.out.println("hi from Bar method go ");}
}
public static void main (String [] args) {
Foo f = new Foo();// foo constoru
f.makeBar();
}
void makeBar() {
(new Bar() {}).go();
}
}





1 compile time error
2 Runtime Error
3 foo outerconstructor , bar constructor , hi fromm bar method go
4
5 None of these
3

Q 99

public class etattva101 {

public static void main(String[] args) {
final int a; // Line 1
final int b; // Line 2
b=10; // Line 3
class MethodLocalClass {

int i =12;
a=19; // Line 4
}
}







1 compile time error in line 4
2 Runtime Error
3
4
5 None of these
1




Q 100

class MainClassForAandB
{

static class A {
void process() throws Exception {
throw new Exception();
}
}

static class B extends A {
void process() { System.out.println("B "); }

}

public static void main(String[] args) {
A a = new B();
a.process();//19


}

}





1 compile time error
2 Runtime Error
3
4
5 None of these
1


===================