Вот главный классКонструктор подкласса
**
** Assignment class
**
** This class represents an Assignment.
**
****************************************************/
public class Assignment {
private String name;
private double pointsPossible;
private double pointsEarned;
// Assignment constructor
//
// postcondition: all instance variables are initialized with
// the given values.
public Assignment (String n, double ptsPoss, double ptsEarned) {
name =n;
pointsPossible=ptsPoss;
pointsEarned=ptsEarned;
}
// getName accessor method
//
// postcondition: returns the name of this Assignment public
String getName() {
return name;
}
// getPointsPossible accessor method
//
// postcondition: returns the points possible for this Assignment
public double getPointsPossible() {
return pointsPossible;
}
// getPointsEarned accessor method
//
// postcondition: returns the points earned for this Assignment
public double getPointsEarned() {
return pointsEarned;
}
}
и когда я пытаюсь использовать мои аксессор в моем подклассе я получаю сообщение об ошибке при попытке инициализировать свой переменные
здесь подкласс
import java.util.ArrayList;
/****************************************************
**
** CategoryAssignment class
**
** This class represents an CategoryAssignment.
** Do not add any additional methods to this class.
**
****************************************************/
public class CategoryAssignment extends Assignment {
// declare any new instance variables that you need here
// don't forget to make them private!
// don't declare more that you really need!
// CategoryAssignment constructor
//
// postcondition: all instance variables are initialized with
// the given values.
public CategoryAssignment (String n, double ptsPoss, double ptsEarned, String cat) {
}
// getCategoryName accessor method
//
// postcondition: returns the name of the category associated
// with this CategoryAssignment
public String getCategoryName() {
return cat;
}
}
Я не могу заставить переменные подкласса инициализировать. Кроме того, если это будет проект класса книги, было бы разумно хранить переменную категорий в массиве или ArrayList?
Какая ошибка? пожалуйста, покажите stacktrace. Кроме того, пожалуйста, правильно отформатируйте код – ItamarG3
Я никогда не вижу 'cat', определенный в классе. – Compass