In this section we will learn about abstract classes
Abstract class – in-depth discussion
Abstract classes are one of the more important classes in Java.
1. When you use the abstract keyword to modify a class, this class is an abstract class.
2, when using the abstract keyword to modify a method, this method is an abstract method.
3. Abstract abstractions in abstract classes are not allowed to be implemented in abstract classes, and once implemented are not abstract methods and abstract classes. Abstract abstraction methods can only be implemented in subclasses.
4, the abstract class can have the implementation method.
5, the abstract method in the programming is not a lot, but in the company's written test, but the examiner is more love to ask the knowledge points.
Abstract class – Considerations
1. Abstract classes cannot be instantiated
2. Abstract classes do not necessarily include abstract methods. In other words, abstract classes can have no abstract abstraction method.
3. Once the class contains an abstract abstraction, the class must be declared abstract.
4, abstract methods can not have a subject.
Example of correct abstract method: abstract void ABC ();
Example of an abstract method of the wrong language: abstract void abc () {}
Package abstractclass; Public class abstractclass { Public Static voidMain (string[] args) {//TODO auto-generated method stub //animal an=new Animal (); Abstract class does not allow instantiationAnimal an=NewCat (); An.cry (); AN.SX (); an=NewDog (); An.cry (); AN.SX (); }}//abstract class keywordsAbstract class Animal{String name;intAge//animal will be called, using abstract abstraction method Abstract Public voidCry ();Abstract Abstract method can not be used in the abstraction class //Abstract class can have an implementation method Public voidSX () {System.out.println ("Implementation Method"); }}//When a subclass inherits a parent class that is abstract, it requires the programmer to implement all the abstract methods of the abstract class. class Cat extends Animal{ //Implements the cry of the parent class, in fact similar to the subclass in the previous section of learning overriding the parent class Public voidCry () {System.out.println ("Cat's name."); }} class Dog extends Animal{ //Implements the cry of the parent class, in fact similar to the subclass in the previous section of learning overriding the parent class Public voidCry () {System.out.println ("bark."); }}
In the next section, we'll talk about interface classes, and we want to be able to compare them on abstract classes and interface classes.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java Multi-State Learning 3