/*
形式参数
基本类型:
引用类型:
类:当你看到一个类作为方法参数类型的时候,将来调用时需要传递该类及其该类的子类对象
抽象类:当你看到一个抽象类作为方法的参数类型的时候,将来调用时需要传递继承该抽象类的具体子类对象
接口:当你看到一个接口作为方法参数类型的时候,将来调用时需要传递实现该接口的具体子类对象
*/
类
class Demo1 {
public void fun1() {
System.out.println("好好学习,天天向上!");
}
}
class Demo1Zi extends Demo1{
}
class Demo1Test {
public void show(Demo1 demo1) { //Demo1 demo1 = new Demo1Zi()
demo1.fun1();
}
}
public class StudentDemo1 {
public static void main(String[] args) {
Demo1Test demo1Test = new Demo1Test();
demo1Test.show(new Demo1());
demo1Test.show(new Demo1Zi());
}
}
抽象类
abstract class Demo2{
public abstract void fun1();
}
class Demo2Zi extends Demo2{
@Override
public void fun1() {
System.out.println("魏一民真帅!");
}
}
class Student2{
public void show(Demo2 demo2){ //Demo2 demo2 = new Demo2Zi()
demo2.fun1();
}
}
public class StudentDemo2 {
public static void main(String[] args) {
Student2 student2 = new Student2();
student2.show(new Demo2Zi());
}
}
接口
interface Inter1{
public abstract void fun1();
}
class Inter1Impl implements Inter1{
@Override
public void fun1() {
System.out.println("陈真也很帅!");
}
}
class Student3{
public void show(Inter1 inter1){ //Inter1 inter1 = new Inter1Impl() 接口多态
inter1.fun1();
}
}
public class StudentDemo3 {
public static void main(String[] args) {
Student3 student3 = new Student3();
student3.show(new Inter1Impl());
}
}
标签:传参,fun1,show,void,public,day10,new,抽象类,class
From: https://www.cnblogs.com/qiwei-bigdata/p/18345845