跟我一起学编程[第二季 JAVA篇(1)]

前言

说到考试,其实就是通过训练人不像人,考方自然是不把人当人。Sun Cer­ti­fied Java Pro­gram­mer (SCJP) 也不例外,这个考试需要选拔的就是能当java编译器/jdk 用的活人!

说难不难,除了规则没有很多深奥的东西;说简单也不简单,要记好这些规则并把它们变成自己的神经反应需要花上一些功夫。那从今天起,我就来继续“跟我一起学编程”系列。这一次,文章可能会写得像笔记(没有衔接语来承上启下),但是可以保证的是它至少是按照逻辑走的。还有,为了减小理解偏差,有些部分我可能会用比较多的英文写。关键词会用斜体标出。

最后希望那些想拿SCJP的同胞们能从这个系列得到深远的帮助!

Chap­ter 1. Dec­la­ra­tions, Ini­tial­iza­tion and Scoping

Develop code that declares classes (includ­ing abstract and all forms of nested classes), inter­faces, and enums, and includes the appro­pri­ate use of pack­age and import state­ments (includ­ing sta­tic imports).

Class dec­la­ra­tion define new ref­er­ence types and describe how they are implemented.

A nested class is any class whose dec­la­ra­tion occurs within the body of another class or inter­face. 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 incom­pletely imple­mented; such a class can­not be instan­ti­ated, but can be extended by sub­classes. A class may be declared final, in which case it can­not have sub­classes. If a class is declared pub­lic, then it can be referred to from other packages.

Each class except Object is an exten­sion of (that is, a sub­class of) a sin­gle exist­ing class and may imple­ment inter­faces. The body of a class declares mem­bers (fields and meth­ods and nested classes and inter­faces), instance and sta­tic ini­tial­iz­ers, and con­struc­tors. The scope of a mem­ber is the entire dec­la­ra­tion of the class to which the mem­ber belongs. Field, method, mem­ber class, mem­ber inter­face, and con­struc­tor dec­la­ra­tions may include the access mod­i­fiers pub­lic, pro­tected, or pri­vate. The mem­bers of a class include both declared and inher­ited mem­bers. Newly declared fields can hide fields declared in a super­class or super­in­ter­face. Newly declared class mem­bers and inter­face mem­bers can hide class or inter­face mem­bers declared in a super­class or super­in­ter­face. Newly declared meth­ods can hide, imple­ment, or over­ride meth­ods declared in a super­class or superinterface.

Field dec­la­ra­tions describe class vari­ables, which are incar­nated once, and instance vari­ables, which are freshly incar­nated for each instance of the class. A field may be declared final, in which case it can be assigned to only once. Any field dec­la­ra­tion may include an initializer.

Mem­ber class dec­la­ra­tions describe nested classes that are mem­bers of the sur­round­ing class. Mem­ber classes may be sta­tic, in which case they have no access to the instance vari­ables of the sur­round­ing class; or they may be inner classes.

Mem­ber inter­face dec­la­ra­tions describe nested inter­faces that are mem­bers of the sur­round­ing class.

Method dec­la­ra­tions describe code that may be invoked by method invo­ca­tion expres­sions. A class method is invoked rel­a­tive to the class type; an instance method is invoked with respect to some par­tic­u­lar object that is an instance of the class type. A method whose dec­la­ra­tion does not indi­cate how it is imple­mented MUST be declared abstract. A method may be declared final, in which case it can­not be hid­den or over­rid­den. A method may be imple­mented by plat­form depen­dent native code. A syn­chro­nized method auto­mat­i­cally locks an object before exe­cut­ing its body and auto­mat­i­cally unlocks the object on return, as if by use of a syn­chro­nized state­ment, thus allow­ing its activ­i­ties to be syn­chro­nized with those of other threads.

Method names may be overloaded.

Instance ini­tial­iz­ers are blocks of exe­cutable code that may be used to help ini­tial­ize an instance when it is created.

Sta­tic ini­tial­iz­ers are blocks of exe­cutable code that may be used to help ini­tial­ize a class when it is first loaded.

Con­struc­tors are sim­i­lar to meth­ods, but can­not be invoked directly by a method call; they are used to ini­tial­ize new class instances. Like meth­ods, they may be overloaded.

To Be Con­tin­ued

CBlog

About Conan

博客,好学者,开源控,爱编程,喜设计,迷摄影,爱音乐。好学对象:平面设计,网站架构,算法,网络安全,视觉艺术。