我如何创建抽象对象 class?
How I created objects of an abstract class?
- 为什么
GeometricObject[] abstractObjects = new GeometricObject[10];
不会导致我创建抽象对象 class 的错误?
A[] objects;
和A[] objects = new A[7];
有什么区别
public class Test
{
public static void main(String[] args)
{
int[] numbers = new int[8];
A[] objects = new A[7];
GeometricObject[] abstractObjects = new GeometricObject[10];
System.out.println(numbers[3]); // prints 0
System.out.println(objects[4]); // prints null
System.out.println(abstractObjects[6]); // prints null
}
}
abstract class GeometricObject {}
class A
{
public int number;
A()
{
number = 13;
}
}
GeometricObject[] abstractObjects = new GeometricObject[10];
您不是在此处创建 GeometricObject 的对象。
您正在创建一个数组对象(GeometricObject class
类型)。
What's the difference between A[] objects; and A[] objects = new
A[7];
A[] objects = new A[2]
分为两部分
A[] objects
- 它称为物体减速。
new A[7]
- 调用了对象的初始化
- 为什么
GeometricObject[] abstractObjects = new GeometricObject[10];
不会导致我创建抽象对象 class 的错误? A[] objects;
和A[] objects = new A[7];
有什么区别
public class Test
{
public static void main(String[] args)
{
int[] numbers = new int[8];
A[] objects = new A[7];
GeometricObject[] abstractObjects = new GeometricObject[10];
System.out.println(numbers[3]); // prints 0
System.out.println(objects[4]); // prints null
System.out.println(abstractObjects[6]); // prints null
}
}
abstract class GeometricObject {}
class A
{
public int number;
A()
{
number = 13;
}
}
GeometricObject[] abstractObjects = new GeometricObject[10];
您不是在此处创建 GeometricObject 的对象。
您正在创建一个数组对象(GeometricObject class
类型)。
What's the difference between A[] objects; and A[] objects = new A[7];
A[] objects = new A[2]
分为两部分
A[] objects
- 它称为物体减速。
new A[7]
- 调用了对象的初始化