<< Chapter < Page | Chapter >> Page > |
Revised: Wed May 11 17:31:29 CDT 2016
This page is included in the following Books:
This module contains review questions and answers keyed to the module titled Java4210: Getting Started with Generics .
The questions and the answers are connected by hyperlinks to make it easy for you to navigate from the question to the answer and back again.
True or False: When Java version 1.5 was released, it contained many new language features, including:
True or False: Using Java version1.7, the code shown in Listing 1 will compile without warnings, errors, or other messages being generated by thecompiler.
Listing 1 - Question 2 |
---|
/*File Q02.java
************************************************/import java.util.*;
public class Q02{ArrayList var1 = new ArrayList();void runIt(){
var1.add(new Date());//Note the required cast in the following
// statement.System.out.println(
((Date)var1.get(0)).getTime());}//runIt
public static void main(String[]args){
new Q02().runIt();}//end main}//end class Q02
//=============================================// |
Generics was introduced in Java v1.5 to provide which of the following:
True or False: The use of generics is limited to the Java Collections framework.
True or False: The Java v1.7 compiler produces an error message when an attempt is made to compile the code shown in Listing 1 .
True or False: When the code in Listing 1 is compiled using the -Xlint:unchecked switch with Java v1.7, the compiler produces:
True or False: The program code shown in Listing 2 will compile and execute successfully to produce an output similar to that shownin Figure 1 .
Listing 2 - Question 7. |
---|
/*File Q07.java
************************************************/import java.util.*;
public class Q07{ArrayList var1 = new ArrayList();void runIt(){
var1.add(new Date());System.out.println(
(var1.get(0)).getTime());}//runIt
public static void main(String[]args){
new Q07().runIt();}//end main}//end class Q07
//=============================================// |
Figure 1 - Question 7. |
---|
1378054267172 |
What modification must be made to the code shown in Listing 2 to cause it to compile and execute successfully?
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?