Interface exercises, teacher student

Working class:

/** encapsulate this function in an interface * / public interface working {void sendad(); / / the methods in the interface are decorated with public abstract by default

}

Student class:

/** define a student class to implement a work interface * a class implements an interface and needs to rewrite the abstract methods in the interface * this class has the functions specified in the interface * / public class student implements working {@ override public void sendad() {system. Out. Println ("student sends flyers...);}

}

Teacher class:

Public class teacher implements working {@ override public void sendad() {system.out.println ("advertising");}

}

Test demo class:

/** working students * / public class demo {public static void main (string [] args) {student stu1 = new student(); stu1. Sendad(); teacher Tc1 = new teacher(); Tc1. Sendad();}}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>