<< Chapter < Page | Chapter >> Page > |
Figure 2 - Question 2. |
---|
Frame title
JInternalFrame title |
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
************************************************/public class Q03{
/*Integer and Double are both subclasses of
Number. Both classes define a method nameddoubleValue that returns the encapsulated
numeric value as type double.*/
public static void main(String[]args){
Foo<Integer>iFoo = new Foo<Integer>(15);
System.out.println(iFoo.get().doubleValue());Foo<Double>dFoo = new Foo<Double>(1.0/3);
System.out.println(dFoo.get().doubleValue());displayClassI(iFoo);
displayClassD(dFoo);}//end main
//-------------------------------------------//static void displayClassI(Foo<Integer>obj){
System.out.println(obj.getClass());}//end displayClassI
//-------------------------------------------//static void displayClassD(Foo<Double>obj){
System.out.println(obj.getClass());}//end displayClassD
}//end class Q03//=============================================//
class Foo<T extends Number>{
private T obj;public Foo(T obj){
this.obj = obj;}//end constructor
public T get(){return obj;
}//end get}//end Foo
//=============================================// |
Figure 3 - Question 3. |
---|
15.0
0.3333333333333333class Foo
class Foo |
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
************************************************/import java.awt.Frame;
import javax.swing.JInternalFrame;import java.awt.Container;
/*Frame and JInternalFrame are both subclasses of
Container. Both classes define a constructorthat accepts a String as a title. Both classes
define a method named getTitle that returns thetitle string.
*/public class Q04{
public static void main(String[]args){
Foo<Frame>fFoo =
new Foo<Frame>(
new Frame("Frame title"));System.out.println(fFoo.get().getTitle());
Foo<JInternalFrame>jFoo =
new Foo<JInternalFrame>(
new JInternalFrame("JInternalFrame title"));
System.out.println(jFoo.get().getTitle());
displayClassF(fFoo);displayClassJ(jFoo);
}//end main//-------------------------------------------//
static void displayClassF(Foo<Frame>obj){
System.out.println(obj.getClass());}//end displayClassF
//-------------------------------------------//static void displayClassJ(
Foo<JInternalFrame>obj){
System.out.println(obj.getClass());}//end displayClassJ
}//end class Q04//=============================================//
class Foo<T extends Container>{
private T obj;public Foo(T obj){
this.obj = obj;}//end constructor
public T get(){return obj;
}//end get}//end Foo
//=============================================//
Figure 4 - Question 4. |
---|
Frame title
JInternalFrame titleclass Foo
class Foo |
True or False: The code shown in Listing 5 will compile and run successfully producing the output shown in Figure 5 .
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?