Java programming ideas fourth edition Chapter 6 Personal exercises
Exercise 1: (1) create a class in a package and create an instance of the class outside the package of the class.
Import mil. oms. main. test. test; public class MainTest {public static void main (String args []) {Test test = new Test ();}/** Test () instantiation of the running result ...... */}
Package mil. oms. main. test; public class Test {public Test () {System. out. println ("Test () instantiate ...... ");}}
Exercise 2: (1) rewrite the code snippets in this Section into a complete program and verify the actual conflicts.
import mil.oms.main.test.Vector;import java.util.*;public class MainTest { public static void main(String args[]){ Vector vector=new Vector(); java.util.Vector vector1=new java.util.Vector(); }}
Package mil. oms. main. test; public class Vector {public Vector () {System. out. println ("Vector () instantiation ...... ");}}
Exercise 3: (1) create two packages: debug and debugoff. They all contain the same class. This class has a debug () method. The first version shows the String parameter sent to the console, the second version does nothing. It imports the class into a test program using a static import Statement and demonstrates the condition compilation effect.
Import debug. test; public class MainTest {public static void main (String args []) {Test t = new Test (); t. debug ();}/*** running result Test ()...... */}
package debug;public class Test{public void debug(){System.out.println("Test()……");}}
package debugoff;public class Test{public void debug(){}}