我的代码是:-
class Building{}
class Barn extends Building{
public static void main(String[]args){
Building build1 = new Building();
Barn bar1 = new Barn();
Barn bar2 = (Barn)build1;
Object obj1 = (Object)build1;
String str1 = (String)build1; //also an error over here
Building build2 = (Building)bar1;
}
}
我是 Java 新手。所以请任何人都可以解释一下这里是如何进行实例化的,比如如何访问每个对象。
代码中也有错误,请帮助我纠正它。