COMS W 1004x Chapter Notes - Chapter 9: Reserved Word, Method Overriding
Document Summary
Inheritance: it is a relationship between a more general class (called the superclass) and a more specialized class (called the subclass). The subclass inherits data and behavior from the superclass. Its objects automatically have the instance variables that are declared in the superclass. You only declare instance variables that are not part of the superclass objects. The subclass inherits all public methods from the superclass. Subclass constructor: public choicequestion(string questiontext) super(questiontext); choices = new arraylist(); To call a superclass constructor, use the super reserved word in the first statement of the subclass constructor. Polymorphism ( having multiple shapes ) allows us to manipulate objects that share a set of tasks, even though the tasks are executed indifferent ways. To string method: the tostring method returns a string representation for each object. public class bankaccount public string tostring() return bankaccount[balance= + balance + ]; } and in the main method . String s = momssavings. tostring(); // sets s to bankaccount[balance=5000]