COMS W 1004x Chapter Notes - Chapter 9: Reserved Word, Method Overriding

121 views2 pages

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]

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents