/*
返回值类型
基本类型:
引用类型:
类:当你看到一个类作为方法的返回值类型的时候,将来方法内部应该返回该类或该类的子类对象
抽象类:当你看到一个抽象类作为方法的返回值类型的时候,将来方法内部应该返回继承该抽象类的具体子类对象
接口:当你看到一个接口作为方法的返回值类型的时候,将来方法内部应该返回实现了该接口的具体子类对象
*/
类
class Student1{
public void fun1(){
System.out.println("欢迎大家来到数加学院!");
}
}
class Demo1{
public Student1 show(){
return new Student1();
}
}
public class StudentDemo1 {
public static void main(String[] args) {
Demo1 demo1 =new Demo1();
Student1 s1 = demo1.show(); // Student1 s1 = new Student1()
s1.fun1();
System.out.println("s1: "+s1);
Student1 s2 = demo1.show();
System.out.println("s2: "+s2);
}
}
抽象类
abstract class Demo2{
public abstract void fun1();
}
class Demo2Zi extends Demo2{
@Override
public void fun1() {
System.out.println("魏一民是阿里巴巴的高级开发程序员");
}
}
class Student2{
public Demo2 show(){
return new Demo2Zi();
}
}
public class StudentDemo2 {
public static void main(String[] args) {
Student2 student2 = new Student2();
Demo2 d1 = student2.show(); //Demo2 d1 = new Demo2Zi() 抽象多态
d1.fun1();
}
}
接口
interface Inter1{
public abstract void fun1();
}
class Inter1Impl implements Inter1{
@Override
public void fun1() {
System.out.println("昨天南京下冰雹了");
}
}
class Student3{
public Inter1 show(){
return new Inter1Impl();
}
}
public class StudentDemo3 {
public static void main(String[] args) {
Student3 student3 = new Student3();
Inter1 i1 = student3.show(); //Inter1 i1 = new Inter1Impl() 接口多态
i1.fun1();
// Student3 student4 = new Student3();
// Inter1 i2 = new Student3().show();
new Student3()
.show()
.fun1(); // 调用方式:链式调用
}
}