小编ree*_*ing的帖子

如何将子类参数传递给超类私有变量?

我对如何从新对象实例中获取参数也流入超类以更新超类中的私有字段感到困惑。

所以我在一个高级Java课上,并且我的作业需要一个“ Person”超级类和一个扩展“ Person”的“ Student”子类。

Person类存储学生姓名,但它是Student类的构造函数,它接受Person名称。

假设Person中没有方法可以更新变量方法...例如subClassVar = setSuperClassVar();

例如:

public class Person
{
     private String name; //holds the name of the person
     private boolean mood; //holds the mood happy or sad for the person
     private int dollars; //holds their bank account balance
}

class Student extends Person //I also have a tutor class that will extend Person as well
{
     private String degreeMajor //holds the var for the student's major they have for their degree

     Public Student(String startName, int …
Run Code Online (Sandbox Code Playgroud)

java parameters constructor superclass

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

constructor ×1

java ×1

parameters ×1

superclass ×1