java--Abstract class instance (contains static internal abstract class)

Source: Internet
Author: User

Static internal abstract classes can be inherited.

public class Testfather {
public static void Main (string[] args) {
Person.talk2 a = new Newtalk ();
A.get ();
Person Person1 = new Student ("Alice", 20, "female");
System.out.println (Person1.talk ());
/* Person Person2 = new person (); *///abstract class cannot be called

}
}

Abstract class Person {
String name;
int age;
String sex;

Public person (string name, int age, string sex)//wait and try to call the constructor method
{
THIS.name = name;
This.age = age;
This.sex = sex;
}

Public abstract String talk (); Declares an abstract method that can not write its method content

Static abstract class TALK2//internal abstract classes, statically methods can be inherited
{
public abstract void get ();
}
}

Class Newtalk extends Person.talk2 {//Verify the inheritance of internal static classes (equivalent to a separate abstract class)
public void get () {
SYSTEM.OUT.PRINTLN ("Character information:");
}
}

Class Student extends Person {
Public student (string name, Int. age, String sex) {
Super (name, age, Sex); Inheriting parent class construction methods
}

Public String Talk () {
Return "Name:" + name + "Age:" + Ages + "Gender:" + sex;
}
}

java--Abstract class instance (contains static internal abstract class)

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.