Java abstract classes, literacy stickers

Source: Internet
Author: User

Java can also create a class that is specifically used as a parent class, which is called an abstract class. Abstract classes function somewhat like "templates", which are designed to modify and create new classes based on their format. However, it is not possible to create an object directly from an abstract class, but to derive a new class from an abstract class and then create the object.

Abstract class definition rules:
1. Abstract classes and abstract methods must be modified with the abstract keyword.
2, abstract class can not be instantiated, that is, you can not use the new keyword to produce objects.
3. Abstract methods can only be declared, but not implemented.
4. A class containing an abstract method must be declared as an abstract class, and the subclass of the abstract class must replicate all the abstract methods before it can be instantiated, or the subclass is an abstract class.

Declares abstract class person{    String name;    int age;    String occupation;        Declares an abstract method public    abstract String Talk ();} Class Student extends person{public    Student (string name, Int. age, String Occupation)    {        this.name = name;
   
    this.age = age;        this.occupation = occupation;    }        Replication Talk () method public    String Talk ()    {        return "Student---> Name:" +this.name+ ", Age:" +this.age+ ", Occupation:" + this.occupation;}    } Class testabstractdemo1{public    static void Main (String args[])    {        Student s = new Student ("Zhang San", 20, "student");        System.out.println (S.talk ());}    }
   

Java abstract classes, literacy stickers

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.