This article is a mirror article of machine translation, please click here to jump to the original article.

View: 13915|Reply: 0

[Communication] How to use abstract in Java in detail

[Copy link]
Posted on 11/4/2014 9:24:17 AM | | |
abstract modifiers that can modify classes and methods

1. Abstract modifier class, will make this class an abstract class, this class will not be able to generate object instances, but can be used as a type declared by object variables, that is, compile-time types, abstract classes are like semi-finished products of a class, which need to be inherited by subclasses and overwrite the abstract methods.

2. The abstract modification method will make this method an abstract method, that is, there is only a declaration (definition) without implementation, and the implementation part is "; instead. Requires subclass inheritance implementation (override).

Note: A class with an abstract method must be an abstract class. However, abstract classes are not necessarily all abstract methods, but can also be concrete methods.

abstractmodifiers must be placed in the class name when modifying the class.

The abstract modification method requires its subclasses to override (implement) this method. The subclass can be called polymorphically to override (implemented) the method, that is, the abstract method must be implemented in its subclass, unless the subclass itself is also an abstract class.

Note: The parent class is an abstract class, and there are abstract methods in it, so the subclass inherits the parent class and implements (overrides) all the abstract methods in the parent class, so that the subclass has the ability to create instances of objects, otherwise the subclass must also be an abstract class. There can be construction methods in abstract classes, which are the construction methods of the parent class (abstract class) that the subclass needs to call when constructing the subclass object.
Here's a simple example of an abstract class
abstract class E{
public  abstract  void  show(); public abstract can be omitted
}
Then other classes if they inherit it are usually to implement the methods in it
class F extends E{
     void show(){
    Write code for specific implementations
}
}
Finally, if a parent reference is defined in the main method to point to a child object, polymorphism will occur, such as
E e=new F();
e.show();
The show() method in the subclass is actually called





Previous:Detailed explanation of the use of assembly command JMP
Next:Crack the software cannot be used problem, and use OD to skip the judgment of the software
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com