CSCI 1006 Lecture 6: Polymorphism

34 views2 pages
Polymorphism
Polymorphisms allow sharing attributes between different classes.
Java classes can be organized into a hierarchy using superclasses and
subclasses.
Subclasses inherit all instance variables and methods from their
superclasses.
Superclasses are more general.
Every java class is a subclass of object.
Any class can be a superclass.
Any class can be a subclass if its code says “public <Subclass> extends
<Superclass>”.
Subclasses can have new instance variables and methods.
They can also have new definitions of inherited methods. This is known as
overriding.
To use a superclass version of a method, they keyword super is used.
Super refused to an object of the class one level up.
The super( ) constructor, used at the first line of a subclass constructor,
can be used to mimic a constructor from the superclass. Otherwise, if the
super( ) constructor is used later in the code, memory is already allocated,
and it will not run.
In order to allow instance variables to be edited by subclasses, the protection
protected is used.
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Polymorphisms allow sharing attributes between different classes. Java classes can be organized into a hierarchy using superclasses and subclasses. Subclasses inherit all instance variables and methods from their superclasses. Every java class is a subclass of object. Any class can be a subclass if its code says public extends. Subclasses can have new instance variables and methods. They can also have new definitions of inherited methods. To use a superclass version of a method, they keyword super is used. Super refused to an object of the class one level up. The super( ) constructor, used at the first line of a subclass constructor, can be used to mimic a constructor from the superclass. Otherwise, if the super( ) constructor is used later in the code, memory is already allocated, and it will not run. In order to allow instance variables to be edited by subclasses, the protection protected is used.

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

Related Questions