Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Java Data Structures!
You have completed Java Data Structures!
Preview
We'll talk about how to move an object between different classes up and down the inheritance chain.
Copy/Paste
Movie movie = new Movie("Jurassic Park", "Adventure", LocalDate.of(1993, 6, 11));
Definitions
- Type conversion / type casting / type coercion (See 'Casting Objects' section): different ways of, implicitly or explicitly, changing an entity of one data type into another.
- instanceof (See 'The Type Comparison Operator instanceof') - compares an object to a specified type.
- RuntimeException - unchecked exceptions and all exception classes that inherit from here. They do not need to be declared and can happen at any time.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Now for example, if there was a method
that took an object as a parameter,
0:00
we could pass it our movie class,
and because movie is an object,
0:02
everything would work out
fine, implicitly.
0:05
It's possible to also go the other way
and have a parent class
0:08
redefine its type
or explicitly cast itself as a child.
0:11
The switching of a variable
between types is called type conversion,
0:16
or type coercion,
or most commonly known as typecasting.
0:19
Let's pop open JShell in workspaces
so you can get some
0:23
hands-on experience with these concepts.
0:26
Okay,
so let's open up our handy-dandy JShell,
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up