Java Multi-State Learning 3

Source: Internet
Author: User

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

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.