Java abstract class and abstract keyword

Source: Internet
Author: User
Tags abs

The concept of abstract classes:

A class that contains an abstract method is an abstract class

Abstract method:

A method that is declared without being implemented is an abstract method that must be declared with the abstract keyword

It is important to note that

1. When an abstract class quilt inherits, subclasses (if not abstract classes) must override the "all" abstract method in the abstract class

2. Abstract classes cannot be instantiated directly, they need to be instantiated by their subclasses

The definition format of an abstract class:

Abstract class classname{

Property

Method

Abstract methods

}

The code is as follows:

Package Hello;abstract class Abs{private int age;public int. getage () {return age;} public void Setage (int.) {this.age = age;} public void Tell () {}abstract public void Say ();}  Class Demo extends Abs{public void Say () {}}public class Abstractdemo {public static void main (string[] args) {Demo Ademo = New Demo (); System.out.println (Ademo.getage ());}}

  

Java abstract class and abstract keyword

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.