10.1 | Which of the following class definitions defines a legal abstract class?
|
| |
10.2 | The getArea and getPerimeter methods may be removed from the GeometricObject class. What are the benefits of defining getArea and getPerimeter as abstract methods in the GeometricObject class? |
10.3 | Which of the following is a correct interface?
|
10.4 | Two max methods are defined in §10.4. Explain why the max with the signature max(Comparable, Comparable) is better than the one with the signature max(Object, Object) . Are these statements correct? String s = Max.max( "abc" , "efg" ); Date date = Max.max( new Date(), new Date()); |
10.5 | You can define the compareTo method in a class without implementing the Comparable interface. What are the benefits of implementing the Comparable interface? |
10.6 | What would happen if the House class (defined in Listing 10.4) does not override the clone() method or if House does not implement java.lang.Cloneable ? |
10.7 | Show the printout of the following code: java.util.Date date = new java.util.Date(); java.util.Date date1 = (java.util.Date)(date.clone()); System.out.println(date == date1); System.out.println(date.equals(date1)); |
10.8 | Show the printout of the following code: java.util.ArrayList list = new java.util.ArrayList(); list.add( "New York" ); list.add(new java.util.Date()); java.util.ArrayList list1 = (java.util.ArrayList)(list.clone()); System.out.println(list == list1); System.out.println(list.get( ) == list1.get( )); System.out.println(list.get( 1 ) == list1.get( 1 )); |
10.9 | What is wrong in the following code? public class Test { public static void main(String[] args) { GeometricObject x = new Circle( 3 ); GeometricObject y = x.clone(); System.out.println(x == y); } } |
10.10 | Can you assign new int[10] , new String[100] , new Object[50] , or new Calendar[20] into a variable of Object[] type? |
10.11 | Describe primitive-type wrapper classes. Why do you need these wrapper classes? |
10.12 | Are the following statements correct? Integer i = new Integer( "23" ); Integer i = new Integer( 23 ); Integer i = Integer.valueOf( "23" ); Integer i = Integer.parseInt( "23" , 8 ); Double d = new Double(); Double d = Double.valueOf( "23.45" ); int i = (Integer.valueOf( "23" )).intValue(); double d = (Double.valueOf( "23.4" )).doubleValue(); int i = (Double.valueOf( "23.4" )).intValue(); String s = (Double.valueOf( "23.4" )).toString(); |
10.13 | How do you convert an integer into a string? How do you convert a numeric string into an integer? How do you convert a double number into a string? How do you convert a numeric string into a double value? |
10.14 | Why do the following two lines of code compile but cause a runtime error? Number numberRef = new Integer( ); Double doubleRef = (Double)numberRef; |
10.15 | Why do the following two lines of code compile but cause a runtime error? Number[] numberArray = new Integer[ 2 ]; numberArray[ ] = new Double( 1.5 ); |
10.16 | What is wrong in the following code? public class Test { public static void main(String[] args) { Number x = new Integer( 3 ); System.out.println(x.intValue()); System.out.println(x.compareTo(new Integer( 4 ))); } } |
10.17 | What is wrong in the following code? public class Test { public static void main(String[] args) { Number x = new Integer( 3 ); System.out.println(x.intValue()); System.out.println((Integer)x.compareTo(new Integer( 4 ))); } } |
10.18 | What is the output of the following code? public class Test { public static void main(String[] args) { java.math.BigInteger x = new java.math.BigInteger( "3" ); java.math.BigInteger y = new java.math.BigInteger( "7" ); x.add(y); System.out.println(x); } } |
10.19 | Describe the boxing and unboxing features in JDK 1.5. Are the following statements correct in JDK 1.5? Number x = 3 ; Integer x = 3 ; Double x = 3 ; Double x = 3.0 ; int x = new Integer( 3 ); int x = new Integer( 3 ) + new Integer( 4 ); double y = 3.4 ; y.intValue(); JOptionPane.showMessageDialog( null , 45.5 ); |
10.20 | Define the following terms: abstract classes, interfaces. What are the similarities and differences between abstract classes and interfaces? |
10.21 | Indicate true or false for the following statements:
|