0% found this document useful (0 votes)
97 views25 pages

Class Gen (Private T Object Public Gen (T Object) (This - Object Object ) Public T Getobject (Return Object )

This document contains code snippets and questions related to Java programming concepts.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views25 pages

Class Gen (Private T Object Public Gen (T Object) (This - Object Object ) Public T Getobject (Return Object )

This document contains code snippets and questions related to Java programming concepts.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 25

class Gen<T> { 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

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

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

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

interface Displayable extends Reloadable{ public void display();

int[] y= {1,2,4,8,16,32}; System.out.println("output"); for(int x : y){ System.out.print(x); System.out.print(" "); }

reader= new BufferedReader(new FileReader("in")); writer= new PrintWriter(new BufferedWriter(new FileWriter("out")));

while((temp=buffReader.readLine())!=null) System.out.println(temp); } catch(IOException e){

class A has name A class B has name A

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{}

Pi is approxi mately 3.141593 and E is approximately true

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(); }

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

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

String Integer String Integer>() Name,value Set<String>

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();} ------------------------

started ran interrupting ended nomore output

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

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

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

You might also like