Based on Java language

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

The programmer's shop:




1,What is the instance members and members of the class?

Belong to the object instance members, which belong to the object level, it includes the member attribute instance (also known as instance member variables) and instance members, only after the object is created to access the instance member property and instance members method.

       Class member belongs to the class, class member includes members of the class attribute (also known as class member variables) and members of the class methods, through the class can directly access a class member variables and member of the class method calls. Class members do not need to accompany the object, that is to say even if no object, can also refer to members of the class, class member can also through object references. Members of the class to be identified by the keyword static, also known as static members.


2,Member variables and local variables

In the class body variables defined variables declared as part of the class member variables, it is valid in the whole class; and declared in a method variables as local variables, it is only in the definition of its members to be valid, declaring member variables can not use the modifier and static.

Declare a member constants and declare a local constant, although the use of the final keyword, but the statement for the constant member constants must be assigned, and declare a local variable can be the first not to assign a value.

When a local variable and member variables with the same name, member variables will be hidden, then if you want to use a member variable, you must use the this keyword.


(Modifier:


Modifier

Class

Members seek

Construction method

Member variable

Local variables

abstract(Abstract)

static (Static)

public(Public)

protected(Protected)

 

private(Private)

synchronized(Synchronization)

native(The local)

transient(Temporary)

volatie(Volatile)

final(Don't change)

Access modifiers

The same class

The same package

Different package, sub class

Different packages, non sub class

private

 

 

 

protected

 

public

Default

 

 


Finish)

2,break,continue,The default statement

1)break: For suspension of the next case in the switch statement, the statement for exit circulation.

2)continue: Can only be used in recycling, let the program skip the statement, the next cycle.

3)default: Processing the match is not successful in the switch statement.



3,The difference between rewriting and overloading

Rewriting (overriding): also known as override, rewritten or reconstruction, it refers to the class, subclass redefine inherited from the parent class method. It is used between father and son, a method declaration and the parent class with the same name subclasses, which covers the parent class method. Reconstruction to solve the problem of difference subclass and superclass. Method override the need to follow the rules are as follows:

1.

The method name must be the same,

2.

The return value data types to be the same,

3.

The parameters used to be the same,

4.

Modifier permissions can only more open, not closed. public-->protected-->(default/package)-->private

5.

Method modified by final will no longer be rewritten.


Heavy load (overloading): refers to the same class, there are multiple methods with the same name, but different parameter list method, suitable for different call. Popular to say yes but distinguishable methods within a class declares multiple of the same name. Heavy duty also has rules to follow:

1.

Method name must be the same,

2.

Parameter type passed in must be different.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Cynthia at November 14, 2013 - 8:36 PM