Java Learning Note (14-10---14-11 abstract class)

Source: Internet
Author: User
Tags define abstract

"14-10" Object-orientedthe generation of abstract classes/*describe a dog, act, or roar. Describe the Wolf, act, roar. Find similarities between them and can be extracted upward. Of course, they are the common type of extraction, canine division. This kind of things, such as canine, all have the Roar behavior, but the concrete how to call, is indeterminate, is by the concrete subclass to clear. At this time in the description of the canine section, found that some functions are not specific, these non-specific functions, need to be identified in the class, through the Java keyword Abstract (abstract). Classes that define abstract functions must also be decorated with the abstract keyword, and the class that is decorated with the abstractions keyword is an abstraction class *//*the characteristics of an abstract class. 1, abstract classes and abstract methods need to be modified by abstract. Abstract methods must be defined in an abstract class. 2, an abstract class cannot create an instance, because invoking an abstract method is meaningless. 3, only after all abstract methods in the abstract class have been overridden, can its subclasses be instantiated. Otherwise, the subclass is an abstract class. Inheritance, more is the idea, is to face the common type of operation will be more simple. *//*detail Question: 1, is the abstract class the parent class? Yes, because it's constantly being extracted.    2, do abstract classes have constructors?    Yes, although you cannot initialize your own objects, you can initialize your own subclass objects.        Abstract and general class similarities and differences: the same: 1, they are used to describe things, 2, they can define properties and behavior.           Different: 1, the general class can describe things concretely.        Abstract classes describe things that are not specifically information.        2, an abstract class can define more than one member, abstract function. 3, generic classes can create objects, and abstract classes cannot create objects.     3, whether abstract methods can be undefined in an abstract class. Yes, what is the meaning of the existence of this abstract class? Just don't let the class create objects.    4, abstract keywords can not and which keywords to coexist? 1,final (a final decorated class cannot have subclasses, and the definition of an abstract class is to inherit it for subclasses) 2,private (the subclass inherits all the methods of the abstract class to create the object, once it is private, the subclass does not know) 3,static (with the static modified method , it can be called directly by the class name, and the abstract method of invoking the abstract class is useless)*/Abstract classq{ Public Abstract voidHoujiao ();}classDogextendsq{ Public voidHoujiao () {System.out.println ("Bark and bark."); }}classWolfextendsq{ Public voidHoujiao () {System.out.println ("Whining whining"); }}classTest { Public Static voidMain (string[] args) {Wolf Wolf=NewWolf ();    Wolf.houjiao (); }} "14-11 "Object-oriented-Abstract classes of practice*Requirements: The programmer in the company has name, work number, salary, job content. The project manager has a name, work number, salary, job description and bonus. Modeling data for a given requirement. Find the object in the problem area first. Programmer: Properties: Name, job number, salary behavior: Work Item Manager: Property: Name, job number, salary, bonus behavior: Work has been analyzed and found: The programmer and manager are employee employees: attribute: Name, job number, salary behavior: work but employee's Work itself is not specific, should be abstract, by the specific sub-class to reflect*/Abstract classemployee{PrivateString name; PrivateString ID; Private DoublePay ;  PublicEmployee (String name,string ID,DoublePay ) {         This. Name =name;  This. ID =ID;  This. Pay =Pay ; }     Public Abstract voidWork ();}//ProgrammerclassProgrammerextendsemployee{ PublicProgrammer (String name,string ID,DoublePay ) {        Super(Name,id,pay); }     Public voidWork () {System.out.println ("Code ..."); }}//Project ManagerclassManagerextendsemployee{Private DoubleBouns;  PublicManager (String name,string ID,DoublePayDoublebouns) {        Super(Name,id,pay);  This. Bouns =Bouns; }     Public voidWork () {System.out.println ("Manage"); }}classabstracttest{ Public Static voidMain (string[] agrs) {System.out.println (""); }}

Java Learning Note (14-10---14-11 abstract class)

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.