Skip to Main Content
Java
book

Java

by Michael Sikora
January 2003
Beginner to intermediate content levelBeginner to intermediate
150 pages
7h 28m
English
Morgan Kaufmann
Content preview from Java
,, 5.2 The Object Class 5 3
In the first object assignment, the compiler implicitly casts a SavingsAccount type to an
Account type. This is done because all instances of SavingsAceount are also instances of Account
(upcasting). The second object assignment fails at compilation since we are attempting to
implicitly downcast an Account type to a SavingsAccount. Not all instances of Account are also
instances of SavingsAeeount even though in our example we know that fredsAecount contains
an instance of SavingsAccount. We must explicitly downcast, so the following statement would
be valid:
fredsSavingAccount = (SavingsAccount) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JAVA Programming

JAVA Programming

K. Rajkumar
Java Programming

Java Programming

Hari Mohan Pandey
Java Programming

Java Programming

Poornachandra Sarang
Java 9 for Programmers

Java 9 for Programmers

Paul J. Deitel, Harvey Deitel

Publisher Resources

ISBN: 9781558609099