目录
第一题
分析每条语句是否正确
package com.hspedu.poly_.exercise_;
public class PolyExercise01 {
public static void main(String[] args) {
double d = 13.4;
//强制类型转换,变成13
long l = (long)d;
System.out.println(l);//输出13
int in = 5;
//boolean和int不能转换,所以报错
//boolean b = (boolean)in;
//向上转型,编译类型是Object,运行类型是String
//父类Object的对象引用obj指向子类-String类的对象
Object obj = "Hello";
//向下转型,编译类型是String,运行类型是String
String objStr = (String)obj;
//输出Hello
System.out.println(objStr);
//向上转型,编译类型Object,运行类型Integer
Object objPri = new Integer(5);
//承接上句,父类引用objPri指向的是Int