Chapter 10 expand the class structure

Fill in the blank

1, Package Penalty for keywords can define a package,? Import keywords can be imported package.
2, there are four access in Java: Private
__, default_ ___, protected , public .
3, Java can be used ___________ import static package. Class. * ___ introducing all static methods of a class.
. 4, _ JAR command may be labeled as a class all compressed.
5, Java in java.lang
package are automatically imported.
6, Java through __ enum enum keyword definition, this keyword is actually the equivalent of a class that inherits __ the Enum .
7, enumeration by _ values () method to obtain the entire contents of enumeration.

Multiple Choice

1, String and Object class A defined _ package.
A, B the java.lang, Classes in java.util C, D the java.net, the java.sql
2, ___ C permissions can access the same package, package different subclasses can access, non-child class can not access the different packages.
A, Private B, default C, D protected, public
. 3, the following is a correct statement _ C .
A, java.lang.Integer the interface
B, String is defined in the java.util package
C, Double package java.lang class
D, Double class java.lang.object package
4, on the following package, class, and a source description file, not the correct one is C .
A, a packet may comprise a plurality of classes
B, a source file, only one class public
C, belong to the same class of a packet you can not access each other by default, use the import introducing
D, the source file system does not Creating the default package
5, when the keyword is used can not define a class C
.
A, final B, public C, package D, protected

True or False

1, java.lang package must be imported manually by the user, or can not use. (×)
2, full name of the package after the class is defined: class package name. (√)
. 3, can be defined in the enumeration class abstract methods, but only needs to implement the abstract method once. (×)
. 4, the enumeration method may be configured to define, but requires that each enumeration object must call this constructor. (√)
5, the constructor defined in the enumeration can use public rights declaration. (×)

Short answer

1 and their functions outlined package.
A: Use the packages can be functionally similar class unified management, and will avoid the project of the same name in class name conflicts;
2, a brief description of the difference between four access rights of Java.
· Private: only you can access in a class, other classes are not allowed to access;
· default: you can access in one package, but not allow access to different packages;
· protected: can the same package and subclasses of different packages access, like other packages do not allow access;
· public: class can be accessed by all packages.
3, brief enumeration of the role and realize characteristics.
A: enumeration defines a plurality of several examples of a class of objects that can be used, can be directly used enumeration "enumeration type object." The way to obtain the object class instantiation operation.

Programming problem

1, the definition of a brand computer enumeration type, there is only a fixed number of computer brands, such as: Lenovo, HP, Dell, Apple, Acer.

public enum ComputerBrand {
	Lenovo("联想"),HP("惠普"),Dell("戴尔"),Apple("苹果"),Acer("宏碁");
	private String title;宏碁
		this.title=title;
	}
	public String getInfo() {
		return this.title;
	}
}


public class JavaComputerBrand {
       public static void main(String[] args) {
    	ComputerBrand cb=ComputerBrand.Acer;
		System.out.println(cb.getInfo());
	}
}

Results of the

宏碁
Published 162 original articles · won praise 9 · views 3093

Guess you like

Origin blog.csdn.net/ll_j_21/article/details/104698126