Class Gen (Private T Object Public Gen (T Object) (This - Object Object ) Public T Getobject (Return Object )
Class Gen (Private T Object Public Gen (T Object) (This - Object Object ) Public T Getobject (Return Object )
1) compilation fails 2) compilation succeeds 3) Compilation fails 4) compilation succeeds 5) compilation succeeds
1)Compilation fails due to 2nd statement 2)Compilation fails due to 1st statement 3)Compilation succeeds 4)Compilation succeeds
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{}
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(); }
m1(listA) Compiles and runs Without Error m2(listA) Compiles and runs Without Error m1(listB) Compiles and runs Without Error m2(listB) Does Not Compile m1(listO) Does Not Compile m2(listO) Does Not Compile
public void bar(int x){} public int bar(String x){return 1;} public void bar(int x,int y){}
Dog is A Animal Forest Has A Tree Rectangle Has A Side JavaBook is A ProgrammingBook
Private static Single instance; Public final Single getInstance(){ ------------} protected Single(){} protected Single create(){return new Single();} ------------------------
run() :Thread wait() :Object notify() :Object sleep() :Thread start() :Thread join() :Thread
public class MyInt implements Comparable{ ................ public int compareTo(Object o){ MyInt i2=(MyInt)o; return i-i2.i; }
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
public class GenericB<T extends Pet>{ public T foo; public void setFoo(T foo){} public T getFoo{return foo;} }
public int update(int quantity,int adjust){ quantity = quantity+adjust; return quantity; } public void callUpdate(){ int quant=100; quant=update(quant,320); }
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; }
public static void main(String[] args){ TestTwo t=new TestTwo(); t.start(); t.join(); t.run(); t.doit(); }
1)compilation succeeds 2)compilation fails 3)compilation succeeds 4)compilation succeeds 5)compilation fails
public static void main(String[] args){ List<String> list =new LinkedList<String>(); -----------------------------System.out.println(list.get(0).length()) }
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){}
package alpha; public class Alpha{ private String alpha; public Alpha(){ this("A"); } protected Alpha(String a){ alpha=a; } } package beta; public class Beta extends alpha.Alpha{ public Beta(String a){super(a);} }
................ public static int doubleMe(int h){ return h*2 } ................... ................... method call should be amount=Doubler.doubleMe(amount); .................. .................
SortedSet : defines base methods for an 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