You are on page 1of 12

Q 105,316

==========
package com.bar;
import com.foo.bar.blatz.*;
import com.foo.bar.*;

Q 21,124
========

interface Reloadable
{
public void reload90;
}

class Edot
{
public void Edit(){}
}

interface Displayable extends Reloadable


{
public void display();
}

Q113.244
============
import java.util.*;
public class NumberNames
{
private HashMap<String,Integer> map= new HashMap<String,Integer>();

public void put(String name, int value)


{
map.put(name,value);
}
public Set<String> getNames()
{
for(String aaa:map.keySet())
System.out.println(map.get(aaa));
return map.keySet();
}

public static void main(String[] ars)


{
NumberNames nn=new NumberNames();
nn.put("10",4);
nn.put("11",14);
nn.put("12",24);
nn.put("13",34);
nn.put("14",44);
nn.put("15",54);
nn.put("6",64);

System.out.println(nn.getNames());
}
}
Q 106
=========

import java.util.*;

class A{}
class B extends A{}

public class Test


{
public static void main(String[] args)
{
List<A> listA=new LinkedList<A>();
List<B> listB=new LinkedList<B>();
List<Object> listO=new LinkedList<Object>();

m1(listA);
m1(listB);
//m1(listO);
m2(listA);
//m2(listB);
m2(listO);
}
public static void m1(List<? extends A> list){}
public static void m2(List<A> list){}

Q 42,177
========:

BufferedReader reader = new BufferedReader(new FileReader("in"));


PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter("out")));

Q 49,335
=========:

(temp=buffReader.readLine())!=null

(IOException e){

Q 7,195
==========

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

//ArrayList<String> x1=new ArrayList<String>();


//foo(x1);
//ArrayList<Object> x2=new ArrayList<String>();
//foo(x2);
ArrayList<Object> x3=new ArrayList<Object>();
foo(x3);
ArrayList x4=new ArrayList();
foo(x4);
}

public static void foo(List<Object> list)


{
}
}

Q 6,238
=========

import java.util.*;
public class NumberNames1
{
public void takeList(List<? extends String> list)
{
//list.add("foo");
list=new ArrayList<String>();
//list=new ArrayList<Object>();
String s=list.get(0);
Object o=list;

}
}

Q 12
========:

class Alpha
{
public void foo(String... args)
{
System.out.println("Alpha:foo");
}
public void bar(String a)
{
System.out.println("Alpha:bar");
}
}

public class Beta extends Alpha


{
public void foo(String a)
{
System.out.println("Beta:foo");
}
public void bar(String a)
{
System.out.println("Beta:bar");
}
public static void main(String[] args)
{
Alpha a=new Beta();
Beta b=(Beta)a;

a.foo("test");b.foo("test");
a.bar("test");b.bar("test");
}
}

o/p

Alpha:foo
Beta:foo
Beta:bar
Beta:bar

Q15
=====

enum Element
{
EARTH,WIND,FIRE{
public String info(){
return "Hot";
}
};

public String info()


{
return "element";
}
}

Q20
=======

package com.sun.cert;
import java.util.*;
public class AddressBook
{
ArrayList entries;
}

Q52
=====

class A has name A


class B has name A

Q 287,305
=========

public
private
public
public
public
public

Q 246
======

import java.util.*;

public class TestGen


{
public static void main(String[] args)
{
List<String> list = new LinkedList<String>();
list.add("one");
list.add("two");

System.out.println(list.get(0).length());
}
}

Q243
=======

import java.util.*;

public class TestGen1


{
public void main(String[] args)
{
ArrayList<Dog> list = new ArrayList<Dog>();
takeList(list);
}

//public void takeList(ArrayList list){} // compiles


//public void tkeList(ArrayList<Animal> list){}
//public void takeList(ArrayList<? extends Animal> list){} // compiles
//public void takeList(ArrayList<?> list){} // compiles
//public void tkeList(ArrayList<Object> list){}

class Animal{}
class Dog extends Animal{}

QUESTION # 187,248
====================
public class MyInt implements Comparable {
------
}
public int CompareTo(Object o) {
----
return i-i2.i;
}

EXPLANATION:
sort() method in Collections class uses ompareTo() method of Comparable interface.
so we have to override that compareTo() method. since the o/p should be in
ascending order, i-i2.i is returned.

QUESTION # 143
===============

protected Single() { }

static Single create() { -- }

QUESTION # 5
=============

public class Gen<T> {


private T object;
public Gen(T object) {
this.object=object;
}
public T getObject() {
return object;
}

Q;42
===========

BufferedReader reader = new BufferedReader(new FileReader("in"));


PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter("out")));
}

Q91,180
==========
public boolean doesFileExist(String []dirs,String filename)
{
String path="";

for(String dir:dirs)
{

//path=dir; //-------->WONT COMPILE


//path=path.getFile(filename);
path=path+File.separator+dir;
//path=path+getSubdirectory(dir);
}
System.out.println(path);
File file = new File(path,filename);
return file.exists();
}
}

Q # 87
=========
Pi is approximately 3.141593

and E is approximately true

Q 139,288
===========
Dog is-a animal

Forest has-a Tree

Rectangle has-a side

Java Book is-a Programming book

Ans for 217


============
public void bar(int x,int y){}

public int bar(String x){ return 1;}

public void bar(int x){}

Ans for 223,327


=============
public class TesTwo extends Thread
{
public static void main(String[] args) throws Exception
{
TesTwo t=new TesTwo();
t.start();

t.run();
t.join();
t.doIt();
}
public void run()
{
System.out.println(" Run. ");
}
public void doIt()
{
System.out.println(" Doit. ");
}
}

QUESTION # 220,323
=================
public class Flags2
{
private boolean isReady = false;
public synchronized void produce()
{
isReady=true;
notifyAll();
}
public synchronized void consume()
{
while(!isReady)
{
try
{
wait();

}catch(Exception ex){}
}
isReady=false;//I THINK WE MUST PLACE "false" HERE....if we place "true" then
wait() method is never invoked again (isReday's value is always true)
}
}

Ans for #147,222


===============
started
ran
interrupting
ended
(no more output)

question 5,353:
===========
public class Gen<T> {
private T object;
public Gen(T object) {
this.object=object;
}
public T getObject() {
return object;
}

question 6,238
===============
public void takeList(List<? extends String> list)
{
//list.add("foo");
list=new ArrayList<String>(); // compiles
//list=new ArrayList<Object>();
String s=list.get(0); // compiles
Object o=list; // compiles
}
Qustion: 7
==============
import java.util.*;
public class X
{
public static void main(String[] args)
{

ArrayList<String> x1=new ArrayList<String>(); -- compiles


foo(x1); -- fails

ArrayList<Object> x2=new ArrayList<String>(); -- fails


foo(x2); -- fails

ArrayList<Object> x3=new ArrayList<Object>(); -- compiles


foo(x3); -- compiles

ArrayList x4=new ArrayList(); -- compiles


foo(x4); -- compiles
}

public static void foo(List<Object> list)


{
}
}

question 15:
============
enum Element
{
EARTH,WIND,FIRE{
public String info(){
return "Hot";
}
};
public String info()
{
return "element";
}
}

question 20:
==============
package com.sun.cert;
import java.util.*;
public class AddressBook
{
ArrayList entries;
}

question 21:
============
interface Reloadable
{
public void reload();
}

class Edit
{
public void Edit(){}
}

interface Displayable extends Reloadable


{
public void display();

question 37
============
for(int x : y)

question 49,335
===============
(temp=buffReader.readLine())!=null

(IOException e){

question 12:
===============
Alpha:foo Beta:foo Beta:bar Beta:bar

question 52
===============
class A has name A
class B has name A

question 251,336
=============
import java.io.*

public class ReadFile{


public static void main(String argv[]){
try{
File x1 = new File("MyText.txt");
FileReader x2 = new FileReader(x1);
BufferedReader x4 = new BufferedReader(x2);
String x3 = null;
while((x3 = x4.readLine()) != null){
System.out.println(x3);
}x4.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
}

question 329,151
================
run() --->java.lang.Thread
wait() --->java.lang.Object
notify() --->java.lang.Object
sleep() --->java.lang.Thread
start() --->java.lang.Thread
join() --->java.lang.Thread

Q200,313
============
public int update(int quantity, int adjust){
quantity=quantity + adjust;
return quantity;

public void callUpdate(){

int quant=100;
quant=update(quant,320);
system.out.println("quant="+quant;)

Q-308
=============
public class Doubler {
public static int doubleMe(int h)
{
return h*2;

public class Holder {

int amount=10;
public void doubleAmount(amount);}

Q-362
===============
java.util.SortedSet->>>>>defines base methods fr an ordered set..

import java.util.Arrays->>>>>provide array manipulation utilities..

import java.util.Iterator-->>>>>>defines methods fr leniar access to a


collection...

java.util.TreeSet->>>>> provide concrete implementaion of an ordered set..


java.util.Collection->>>>>defines base methods for all collection object

Q 183
========

Scanner scanner = new Scanner("one,5,true,3,true,6,7,false");


scanner.useDelimiter(",");
while(scanner.hasNext())
{
if(scanner.hasNextBoolean())
{
System.out.println(scanner.nextBoolean());
}
else
{
scanner.next();
}

Q-188
========
java.util.map===> defines the method: get(Object key)
java.util.Set===> contains no pair of elements e1 and e2 such that e1.equals?(e2)
java.util.List===> allows access to elements by their integer index
java.util.Queue===> is designed for holding elements prior to processing

Q-199
========
T extends Pet
T
T
T

Q-53
=======

Car is a Vehicle and Car is a Collactable===> class A implements B,C {}


Car has a SteeringWheel===> class A {B b;}
Car has Wheels===> class A{ List<B> b;}
Mini is a Car & Car is an Object===>class A extends B{}

You might also like