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

Source: Internet
Author: User

                                                                          Program Liu Congcong Public  interface sing {public static final string eyecolor= "BLACK";p ublic  Void sleep ();p ublic void sing ();} public interface print {public static final string sex= "Woman";p ublic  Void print ();p ublic 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 student of the name" +name+ "is a person who likes to sing");} 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 (+);         t1.sing ();         t1.sleep ();         print p1= (Print) t1;          //(object type Cast)         p1.print ();         p1.eat ();         teacher t2= (Teacher) t1;         t2.info ();}}


This article is from the "secret of Technology" blog, so be sure to keep this source http://liucongcong.blog.51cto.com/11527480/1774876

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

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.