<< Chapter < Page Chapter >> Page >
Figure 2 - Question 2.
Frame title JInternalFrame title

Answer 2

Question 3

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

Answer 3

Question 4

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

Answer 4

Question 5

True or False: The code shown in Listing 5 will compile and run successfully producing the output shown in Figure 5 .

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask