Anda di halaman 1dari 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-188,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

Anda mungkin juga menyukai