class student{
public void study(){
System.out.println("Good Good study,day day up");}}
class studentDemo{
public void method(student s){
s.study();}}
public class main {
public static void main(String[] args){
// TODO Auto-generated method stub
studentDemo t=new studentDemo();
student ss=new student();
t.method(ss);}}
抽象类:需要的的是抽象类的子类对象
package test10;
abstract class person{
public abstract void study();}
class personDemo{
public void method(person p){
p.study();}}
//定义一个具体的学生类
class student extends person{
public void study(){
System.out.println("good good study");}}
public class main {
public static void main(String[] args){
// TODO Auto-generated method stub
//通过personDemo来调用方法
personDemo d=new personDemo();
person p=new student();//通过多态的方式,来给抽象类定义一个具体类
d.method(p);}}
接口:需要的是实现该接口类的对象
package test10;
interface Love{
public abstract void love();}
class LoveDemo{
public void method(Love l){
l.love();}}
//这里需要定义一个具体类来实验
class Teacher implements Love{
public void love(){
System.out.println("love");}}
public class main {
public static void main(String[] args){
// TODO Auto-generated method stub
//通过LoveDemo来调用方法
LoveDemo d=new LoveDemo();
Love l=new Teacher();//通过多态的方式来实现
d.method(l);}}