Java Learning Lesson 13th (under Inheritance: Abstract class abstraction)

Source: Internet
Author: User

Abstract: Fuzzy = = Can not understand

Inheritance: Discovering commonalities between things and extracting them upward to improve code reusability


Things have this function, but this function is what, how to do, do not know, this involves the abstract


1, inheritance: A, b two classes, have show function, the implementation of the same way you can then extract its generality, make a new class, so that a A, a, a, a and a new class.

2, Abstract: A,b two classes, have the function of show, but the implementation of the function is not the same, then the method to extract upward, but the content is not the same , then use the keyword abstract identification, representing the abstract function, Then this class must also be marked with an abstract, representing an abstraction class


Abstract class c{abstract void Show ();} Class A extends C{void show () {System.out.println ("A");}} Class B extends C{void show () {System.out.println ("B");}}

Dogs and wolves bark, they all belong to the canine family, and the canine family has a bark function.

As a kind of thing, they all have a function of barking, but how to make sure, this method teaches abstraction.

When a class describes a thing, there is not enough information to describe the thing, and this class is abstract.


Abstract class Canine {abstract void sing ();//four legs, two eyes, running, jumping ...} Class Dog extends {void sing () {System.out.println ("screaming Babies");} 。。。。 }class Wolf extends Canine {void Show () {System.out.println ("barking");} 。。。 }

Ps:java Support multi-language, gray often powerful, development disabled

Continue tomorrow ...

Java Learning Lesson 13th (under Inheritance: Abstract class abstraction)

Related Article

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.