Dark Horse Programmer--java Basic---object-oriented abstraction

Source: Internet
Author: User

------<a href= "http://www.itheima.com" target= "blank" >java training, Android training, iOS training,. NET training </a>, look forward to communicating with you! -------

Object-oriented abstraction

abstract class (abstract)

(1) only the declarations of methods of many classes are extracted, in order to ensure that there is no problem, method declarations are used Abstract decoration.

(2) characteristics of abstract classes

A: If a class has an abstract method, the class must be an abstract class. Abstract classes can have no abstract method inside.

B: Abstract classes are not able to be instantiated. Cannot create an object.

C: If a class inherits an abstract class, it either overrides all abstract methods in the abstract class, or is itself an abstract class.

(3) member features of abstract classes:

A: Member variables: Subclasses can directly inherit member variables from an abstract class. ( the member variables in the abstract class can be the same as before )

B: Member Method: The abstract class is divided into two methods,

One is an abstract method, which must be implemented in a subclass.

One is the common method. Can be directly inherited using the quilt class.

C: Construction Method: Abstract class can not be instantiated, then it has a method of construction ? Abstract class is class , then it has a construction method. Is it useful to construct the method?

There is, in order to let subclass instantiation of time use.

(4) Examples: Examples of teachers, examples of students, examples of employees

(5) related issues with abstract classes:

A: Is there a constructor in an abstract class?

Constructors are basic to objects, without constructors there are no objects.
If the constructor is written and parameterized in the parent class (here is your abstract class), you must write a constructor to invoke the constructor of the parent class in the subclass inheritance.
Example:

1 Abstract classPerson {2 //defines an abstract class that must be inherited3 4 5Person (inti) {6 7 8 }9 }Ten  One  Public classStudentextendsPerson { A  -  - Student () { the  - Super(inti)://the calling parent class constructor method must be displayed//Super Represents the parent class object - } - } +  - If the parent class has no constructor for the parameter, the constructor for the write parent class can not be displayed in the subclass, and Java automatically calls the constructor with no arguments + Example: A Abstract classPerson { at //defines an abstract class that must be inherited -  -  -Person () {//This constructor can also be non-writable, and Java will add a constructor without parameters by default -  -  in } - } to  +  Public classStudentextendsPerson { -  the  * Student () { $ Panax Notoginseng //super ();//can not write, Java will call this super () method itself - } the}

B: Abstract keyword abstraction can not coexist with which keywords?

Private

Private, external directly inaccessible. Subclasses also cannot access

Abstrac

The way to modify it is to let subclasses inherit and override the

Static

then this time the abstract method can be called by the class name, but this is meaningless.

Final

the modified method cannot be overridden. So it conflicts with abstract .

C: Can there be no abstract method in an abstract class?

you can. If you do this, there's only one purpose that won't allow you to create objects of this class

-----------Android Training, Java training, Java Learning Technology blog, look forward to communicating with you! ------------    

Dark Horse Programmer--java Basic---object-oriented abstraction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.