要从StudentJava中的类创建新对象,我们通常使用以下语句
Student std = new Student();
Run Code Online (Sandbox Code Playgroud)
我已经读过new运算符通过在堆中分配内存空间来创建新对象,但是我还读到了调用构造函数Student()创建它.所以,它有点令人困惑.哪一个正在创建对象std?它是new运算符还是默认构造函数?
在以下示例中:
class A {
private int a;
private int b;
private int c;
public A(int a, int b , int c) {
this.a = a;
this.b = b;
this.c = c;
}
}
class B extends A {
public B() {
super(1,2,3);
}
Run Code Online (Sandbox Code Playgroud)
super(1,2,3)在class B创建私有领域一样,在A类的私有字段?或者使用此语句是否违法,因为B不能继承A的私有字段?