You are on page 1of 9

GIVEN BELOW IS THE ANSWERS FOR DRAG AND DROP QUESTIONS GIVEN IN THE

ATTACHMENT SCJP1.

<Question-5>
class Gen<T> {
private T object;
public Gen (T object){
this.object=object;
}
public T getobject(){
return object;
}
public static void main(String[] args) {
Gen<String> str=new Gen<String>("answere");
Gen<Integer> intg=new Gen<Integer>(42);
System.out.println(str.getobject()+"="+intg.getobject());
}
}
<Question-6>

1) compilation fails
2) compilation succeeds
3) Compilation fails
4) compilation succeeds
5)compilation succeeds

<Question-7>

1)Compilation fails due to 2nd statement


2)Compilation fails due to 1st statement
3)Compilation succeeds
4)Compilation succeeds
Nov 7
ashish
<Question-12>

output:

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

<Question-15>

1) EARTH,WIND,
2) FIRE{public String info(){return "HOT"}
3) };
4) public String info(){return "element"}
5) }

<Question-20>

package com.sun.cert;
import java.util.*;

public class AddressBook {


ArrayList list;
}

<Question-21>

interface Displayable extends Reloadable{


public void display();
}

<Question-37>

int[] y= {1,2,4,8,16,32};
System.out.println("output");
for(int x : y){
System.out.print(x);
System.out.print(" ");
}
Nov 7
ashish
<Question-42>

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


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

<Question-49>

class PrintFile{
public static void main (String[] args)
{
try{
while((temp=buffReader.readLine())!=null)
System.out.println(temp);
}
catch(IOException e){
e.printStackTrace();
}
}
}

<Question-52>

class A has name A


class B has name A
Nov 7
ashish
<Question-53>

Car is Vehicle and Collectable class A implements B,C{}


Car Has Steering Wheel class A{B b;}
Car Has Wheels class A{List<B> b;}
Mini is A Car class A extends B{}
Car is an Object class A{}

<Question-87>

Pi is approxi mately 3.141593


and E is approximately true

<Question-91>

public static boolean doesFileExist(String[] directories,String


fileName){
String path="";
for(String dir:directories){
path=path+File.seperator+dir
}
File file=new File(path,fileName);
return file.exists();
}

<Question-105>

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

<Question-106>
m1(listA) Compiles and runs With out Error
m1(listB) Compiles and runs With out Error
m1(listO) Does Not Compile
m2(listA) Compiles and runs With out Error
m2(listB) Does Not Compile
m2(listO) Does Not Compile

<Question-113>

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(){
return map.keySet();
}
}

<Question-123>

public void bar(int x){}


public int bar(String x){return 1;}
public void bar(int x,int y){}
Nov 7
ashish
<Question-124>=<Question-21>

<Question-139>

Dog is A Animal
Forest Has A Tree
Rectangle Has A Side
JavaBook is A ProgrammingBook

<Question-143>

public class Single {


private static Single instance;
public final Single getInstance() {
if(instance==null)
instance=create();
return instance;
}
protected Single(){}
protected Single create(){return new Single();}
}

class SingleSub extends Single{}

<Question-147>

started
ran
interrupting
ended
nomore output

<Question-151>

run() :Thread
wait() :Object
notify() :Object
sleep() :Thread
start() :Thread
join() :Thread

<Question-171>=<Question-52>

<Question-177>=<Question-42>

<Question-180>=<Question-91>

<Question-183>

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

<Question-187>

public class MyInt implements Comparable{

public int compareTo(Object o){


MyInt i2=(MyInt)o;
return i-i2.i;
}
}
<Question-188>

Map defines the Method V get(Object key)


Set contains no pair of elements e1 and e2 , such that e1.equals(e2)
List allow access to elements by their integer index
Queue is designed for holding elements prior to processing

<Question-191>

public class GenericB<T extends Pet>{


public T foo;
public void setFoo(T foo){}
public T getFoo{return foo;}
}

<Question-195>=<Question-7>

<Question-200>

public int update(int quantity,int adjust){


quantity = quantity+adjust;
return quantity;
}
public void callUpdate(){
int quant=100;
quant=update(quant,320);
}
Nov 7
ashish
<Question-217>=<Question-123>

<Question-220>

public class Flags2{


private boolean isReady=false;
public synchronized void produce(){
isReady=true;
notifyAll();
}
public synchronized void consume(){
while(!isReady){
try{
wait();
}catch(Exception e){}
}isReady=false;
}
}

<Question-222>=<Question-147>

<Question-223>

public static void main(String[] args){


TestTwo t=new TestTwo();
t.start();
t.join();
t.run();
t.doit();
}

<Question-238>=<Question-6>

<Question-243>

1)compilation succeeds
2)compilation fails
3)compilation succeeds
4)compilation succeeds
5)compilation fails

<Question-244>=<Question-113>
Nov 7
ashish
<Question-246>

public static void main(String[] args){


List<String> list =new LinkedList<String>();
----------------
---------------
System.out.println(list.get(0).length())
}

<Question-247>

import java.util.*;

public class MyInt implements Comparable {


public static void main(String[] arg) {
ArrayList<MyInt> list=new ArrayList<MyInt>();
list.add(new MyInt(2));
list.add(new MyInt(1));
Collections.sort(list);
System.out.println(list);
}
private int i;
public MyInt(int i) {this.i=i;}

public String toString() { return Integer.toString(i);}

public int compareTo(Object o){

MyInt i2=(MyInt) o;
return i-i2.i;
}
}

<Question-251>

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){
Syso
}
x4.close();
}
catch(Exception ex){}
Nov 7
ashish
<Question-287>

package alpha;
public class Alpha{
private String alpha;
public Alpha(){
this("A");
}
protected Alpha(String s){
alpha=s;
}
}
package beta;
public class Beta extends alpha.Alpha{
public Beta(String a){super(a);}
}

<Question-288>=<Question-139>

<Question-290>=<Question-53>

<Question-305>=<Question-287>

<Question-308>

public static int doubleMe(int h){


return h*2
}
method call should be amount=Doubler.doubleMe(amount);

<Question-313>=<Question-200>

<Question-316>=<Question-105>

<Question-323>=<Question-220>

<Question-327>=<Question-223>

<Question-329>=<Question-151>
Nov 7
ashish
<Question-335>=<Question-49>

<Question-336>=<Question-251>

<Question-346>=<Question-12>

<Question-353>=<Question-5>

<Question-362>

SortedSet : defines base methods for ordered Set


Arrays : provides Array manipulation utilities
Iterator : defines methods for Linear access to a collection
TreeSet : provides a concrete implementation of an ordered set
Collection : defines Base Methods for all collection Objects