前言
说到考试,其实就是通过训练人不像人,考方自然是不把人当人。Sun Certified Java Programmer (SCJP) 也不例外,这个考试需要选拔的就是能当java编译器/jdk 用的活人!
说难不难,除了规则没有很多深奥的东西;说简单也不简单,要记好这些规则并把它们变成自己的神经反应需要花上一些功夫。那从今天起,我就来继续“跟我一起学编程”系列。这一次,文章可能会写得像笔记(没有衔接语来承上启下),但是可以保证的是它至少是按照逻辑走的。还有,为了减小理解偏差,有些部分我可能会用比较多的英文写。关键词会用斜体标出。
最后希望那些想拿SCJP的同胞们能从这个系列得到深远的帮助!
Chapter 1. Declarations, Initialization and Scoping
Develop code that declares classes (including abstract and all forms of nested classes), interfaces, and enums, and includes the appropriate use of package and import statements (including static imports).
Class declaration define new reference types and describe how they are implemented.
A nested class is any class whose declaration occurs within the body of another class or interface. A top level class is a class that is not a nested class.
A named class may be declared abstract and must be declared abstract if it is incompletely implemented; such a class cannot be instantiated, but can be extended by subclasses. A class may be declared final, in which case it cannot have subclasses. If a class is declared public, then it can be referred to from other packages.
Each class except Object is an extension of (that is, a subclass of) a single existing class and may implement interfaces. The body of a class declares members (fields and methods and nested classes and interfaces), instance and static initializers, and constructors. The scope of a member is the entire declaration of the class to which the member belongs. Field, method, member class, member interface, and constructor declarations may include the access modifiers public, protected, or private. The members of a class include both declared and inherited members. Newly declared fields can hide fields declared in a superclass or superinterface. Newly declared class members and interface members can hide class or interface members declared in a superclass or superinterface. Newly declared methods can hide, implement, or override methods declared in a superclass or superinterface.
Field declarations describe class variables, which are incarnated once, and instance variables, which are freshly incarnated for each instance of the class. A field may be declared final, in which case it can be assigned to only once. Any field declaration may include an initializer.
Member class declarations describe nested classes that are members of the surrounding class. Member classes may be static, in which case they have no access to the instance variables of the surrounding class; or they may be inner classes.
Member interface declarations describe nested interfaces that are members of the surrounding class.
Method declarations describe code that may be invoked by method invocation expressions. A class method is invoked relative to the class type; an instance method is invoked with respect to some particular object that is an instance of the class type. A method whose declaration does not indicate how it is implemented MUST be declared abstract. A method may be declared final, in which case it cannot be hidden or overridden. A method may be implemented by platform dependent native code. A synchronized method automatically locks an object before executing its body and automatically unlocks the object on return, as if by use of a synchronized statement, thus allowing its activities to be synchronized with those of other threads.
Method names may be overloaded.
Instance initializers are blocks of executable code that may be used to help initialize an instance when it is created.
Static initializers are blocks of executable code that may be used to help initialize a class when it is first loaded.
Constructors are similar to methods, but cannot be invoked directly by a method call; they are used to initialize new class instances. Like methods, they may be overloaded.
To Be Continued
