<< Chapter < Page | Chapter >> Page > |
Figure 2 - Question 2. |
---|
Object instantiated. |
True or False: The code shown in Listing 3 will compile and run successfully producing the output shown in Figure 3 .
Listing 3 - Question 3. |
---|
/*File Q03.java
************************************************/import java.awt.*;
/*Note the following inheritance hierarchyjava.lang.Object
java.awt.Componentjava.awt.Container
java.awt.Windowjava.awt.Frame
*/public class Q03{
public static void main(String[]args){
Foo<>var = new Foo<Window>();
var.runIt();}//end main
}//end class Q03//=============================================//
class Foo<T extends Component>{
public void runIt(){System.out.println("Object instantiated.");
}//end runIt}//end Foo |
Figure 3 - Question 3. |
---|
Object instantiated. |
True or False: The code shown in Listing 4 will compile and run successfully producing the output shown in Figure 4 .
Listing 4 - Question 4. |
---|
/*File Q04.java
************************************************/public class Q04{
public static void main(String[]args){
Foo<String,Integer>varA =
new Foo<String,Integer>("abcde",500);
System.out.print(varA.get1());System.out.println("," + varA.get2());
Foo<Integer,String>varB =
new Foo<Integer,String>(900,"fghijkl");
System.out.print(varB.get1());System.out.println("," + varB.get2());
}//end main}//end class Q04
//=============================================//class Foo<T1,T2>{
private T1 t1;private T2 t2;
public Foo(T1 t1,T2 t2){this.t1 = t1;
this.t2 = t2;}//end constructor
public T1 get1(){return t1;
}//end get1public T2 get2(){
return t2;}//end get2
}//end Foo |
Figure 4 - Question 4. |
---|
abcde,500
900,fghijkl |
True or False: The code shown in Listing 5 will compile and run successfully producing the output shown in I mage 5 .
Listing 5 - Question 5. |
---|
/*File Q05.java
************************************************/public class Q05{
public static void main(String[]args){
Foo<String,Integer>varA =
new Foo<>("abcde",500);
System.out.print(varA.get1());System.out.println("," + varA.get2());
Foo<Integer,String>varB =
new Foo<>(900,"fghijkl");
System.out.print(varB.get1());System.out.println("," + varB.get2());
}//end main}//end class Q05
//=============================================//class Foo<T1,T2>{
private T1 t1;private T2 t2;
public Foo(T1 t1,T2 t2){this.t1 = t1;
this.t2 = t2;}//end constructor
public T1 get1(){return t1;
}//end get1public T2 get2(){
return t2;}//end get2
}//end Foo |
Figure 5 - Question 5. |
---|
abcde,500
900,fghijkl |
True or False: The code shown in Listing 6 will compile and run successfully producing the output shown in Figure 6 .
Listing 6 - Question 6. |
---|
/*File Q06.java
************************************************/public class Q06{
public static void main(String[]args){
Foo<>varA =
new Foo<String,Integer>("abcde",500);
System.out.print(varA.get1());System.out.println("," + varA.get2());
Foo<>varB =
new Foo<Integer,String>(900,"fghijkl");
System.out.print(varB.get1());System.out.println("," + varB.get2());
}//end main}//end class Q06
//=============================================//class Foo<T1,T2>{
private T1 t1;private T2 t2;
public Foo(T1 t1,T2 t2){this.t1 = t1;
this.t2 = t2;}//end constructor
public T1 get1(){return t1;
}//end get1public T2 get2(){
return t2;}//end get2
}//end Foo |
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?