Java abstract classes and abstract methods

Source: Internet
Author: User

Abstract class:

In Java, a method that has no method body is defined, and the method is implemented specifically by its subclasses.

The method that does not have a method body is called an abstract method, and the class containing the abstract method is an abstract class.

Features of abstract methods:

1. Methods that only the method head has no method body

2. Abstract modification of methods

3. Abstract methods represent an indeterminate operation or behavior

4. Abstract methods cannot be called

Features of abstract classes:

1. Classes that contain abstract methods in definitions are called abstract classes

2. Abstract modification of classes

3. Abstract class represents an abstract object type

4. Abstract classes cannot be instantiated

5. Abstract classes can have specific methods, can have no abstract method

All employees of the company have job number, name, salary and work. Leadership in addition to the employee's attributes and methods there are allowances for public class Employeedemo {public static void main (string[] args) {//TODO auto-generated method Stubjav Ateacher teacher = new Javateacher (001, "Zhang San", +); Teacher.work (); leader lead = new leader (002, "John Doe", 5000,10000); Lead.work ();}} Abstracted class employee{//abstract class private int number;private String name;private double salary;public abstract void work ();//Pumping Like method public employee (int number,string name,double salary) {this.number = Number;this.name = Name;this.salary = salary;} Abstract classes can have not only abstract methods, but also concrete methods public void AA () {System.out.println ("AAA" +number+name+salary);}} A class inherits an abstract class, either implementing a method of an abstract class, or continuing to abstract the class Javateacher extends Employee{public javateacher (int number,string name,double Salary) {super (number,name,salary);} Implementation of the abstract method public void work () {System.out.println ("on Java Lesson");}} Class Leader extends Employee{private double allowance;//grant public leader (int number,string name,double salary,double Allowance) {super (number,name,salary); this.allowance = allowance;} Implementation of the abstract method PuBlic void Work () {System.out.println ("Training new employee, allowance:" +allowance);}} 

Java abstract classes and abstract methods

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.