1. In a class, when the name of the local variable is defined and the name of the member variable is the same, the member variable is hidden and the local variable is used. To use a member variable, you must refer to it by using the keyword this
1 classvariabletest2 {3 intIntTemp = 34;4 voidMethod ()5 {6 intIntTemp = 24;7 intintValue1, intValue2;8IntValue1 =intTemp;9IntValue2 = This. intTemp;Ten System.out.println (intValue1); One System.out.println (intValue2); A - } - Public Static voidMain (string[] args) { theVariabletest Test =Newvaribaletest (); - Test.method (); - } -}
2. The class member method implements the behavior of the class, the general format is as follows:
[modifier] Returns the Type method name (the parameter list of the method) {
Method Statement Body
}
3. In a class, the overloading of a method means that a class can have multiple methods with the same name but the parameters of these methods must be the same, and the difference can be the type of the parameter and the number of arguments.
4, the construction method is usually used to complete the initialization of the object work. The name must be the same as the class name, there is no return value, and the keyword void cannot have
5. In a class, when a simple type is passed to a method, it is passed by value.
6. Object creation includes declaring and allocating memory for an object two steps:
Circle objcircle = new Circle (); Declare a class object to allocate memory space at the same time as the Objcircle
7, in order to better partition the class, Jave provides the package mechanism. A package is a container for classes that separates class name spaces. In a package, all member variables and methods in a class can be accessed by other classes and methods in the same package, in addition to the member variables and methods that are declared private. Packages are declared through the keyword package. The package statement must be the first statement of the Java source file to indicate the packages of the class that the source file defines, in the general format:
Package PackageName;
8. In the declaration of a class, create a subclass of a class by using the keyword extends. The format is as follows:
Class ChildClass extends Fatherclass
If the extends keyword is not used in the declaration of a class, the class is implicitly considered a subclass of object, and object is the class in the Java.lang package.
9, Java does not adopt the multiple inheritance mechanism in the C + + language, inheritance in Java takes single inheritance, that is, each class can have only one parent class.
10, polymorphism: When a class is derived from a parent class, it may be necessary to modify the implementation of a method in the parent class, the polymorphic mechanism can implement methods for different subclasses, but the definition of the method is carried out in a common parent class, and when a method in a subclass is called, the method of the subclass is started. Although the implementation of the method is different among the subclasses, for external calls, it is not necessary to care about the specific implementation, just the common interface.
11, abstract class is a special class in Java. Abstract classes cannot create objects, but can only be created by their derived subclasses. Abstract classes are used exclusively as parent classes of other classes. Abstract classes are defined with the keyword abstract modifier. The abstract is placed before class.
Abstract class ClassName
Use keyword abstract to define abstract methods
Abstract ReturnType methodName ()
12, Java through the interface to achieve the characteristics of multiple inheritance. Defines an interface that is implemented by using the keyword interface.
Interface Interface Name
{
Variables and methods in the interface body
}
In the Java interface, all methods are abstract methods, all variables are static constants
A class declares itself to use one or more interfaces by using the keyword implements. If multiple interfaces are used, the interface names are separated by commas. The format is as follows:
Class ClassName implements Interface1, Interface2
The methods in the interface are all abstract methods, so the class implementing this interface must implement all the methods in the interface. To implement a method of an interface in a class, the name of the method, the return type, the number of arguments, and the type must be exactly the same as the interface.
With the keyword extends, an interface can inherit from another interface with the same syntax as when inheriting a class. When a class implements an interface that inherits from another interface, this class must implement the methods in all interfaces.
The abstract methods in an interface cannot have private and protected modifiers, only public adornments or default.
Java Learning notes (2)