The implementation of abstract methods in the Java applet---interface (solves the problem that the Java language cannot inherit more)

Source: Internet
Author: User

Public interface Sing {
public static final String eyecolor= "Black";
public void sleep ();
public void Sing ();
}

Public interface Print {
public static final String sex= "woman";
public void print ();
public void eat ();
}

public class Student implements sing{
String name;
Public Student (String name) {
This.name=name;
}
Public String GetName () {
return name;
}
public void sleep () {
System.out.println ("Student is Sleeping");
}
public void Sing () {
System.out.println ("Student is SingSong");
}
public void All () {
System.out.println ("The name" +name+ "student is a person who likes singing");
}
}

public class teacher implements sing,print { 
int age;
Public teacher (int age)  {
This.age=age;
}
Public int getage () {
return age;
}
Public void print ()  {
System.out.println ("Teacher is print");
}
Public void eat ()  {
System.out.println ("teacher is eating");
}
Public void sleep ()  {
System.out.println ("teacher is sleeping");
}
public void sing ()  {
System.out.println ("Teacher is singsong");
}
Public void info () {
System.out.println ("This" +age+ "old teacher can sing and draw");
}
}

public class Test {
public static void Main (string[] args) {
Student s1=new Student ("liqing");
S1.sleep ();
S1.sing ();
S1.all ();
Sing t1=new Teacher (25);
T1.sing ();
T1.sleep ();
Print p1= (print) T1; (Object type Cast)
P1.print ();
P1.eat ();
Teacher t2= (Teacher) T1;
T2.info ();
}
}

The implementation of abstract methods in the Java applet---interface (solves the problem that the Java language cannot inherit more)

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.