Java programming ideas fourth edition Chapter 6 Personal exercises

Source: Internet
Author: User

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(){}}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.