Kathryn shows you how to create a constructor and use the this keyword so that you can start building instances from your class blueprint. She also explains how to access different properties of your instance, as well as how to create functions and use them in your program.
- [Instructor] Now that we've created our class blueprint,…we are going to create a constructor.…And in turn, start building some instances.…To build these cars, we need something to construct them.…In Java, that's our constructor method.…So, we are going to go below these variables that we created,…these properties, and we're going to write…public Car, cause that's what we want to create,…int inputAverageMPG,…String inputLicensePlate.…And these are all of our inputs…that we want to initialize our car with.…
And so these are going to be passed through…when we construct an object.…This will all make sense in a minute.…But keeping with this, we'll go Color inputPaintColor,…and then boolean inputAreTaillightsWorking.…And then we'll hit Enter here…so it's a little bit easier to see.…So here, Car is the name of the function…and will be what we create…once the function has finished executing.…
Our inputs to the function are int inputAverageMPG,…a String inputLicensePlate, Color inputPaintColor,…and boolean inputAreTheTaillightsWorking.…
Author
Released
3/21/2018- Downloading Java 9 and choosing an IDE
- Understanding Java basics: data types, strings, arrays, and more
- Controlling flow with functions and loops
- Debugging
- Working with inheritance and interfaces
- Learning lambda
Skill Level Beginner
Duration
Views
Related Courses
-
Advanced Java Programming
with David Gassner3h 33m Advanced
-
Introduction
-
Welcome34s
-
-
1. Getting Started
-
Exploring JShell3m 50s
-
Exploring an IDE2m 11s
-
Hello World in Java4m 6s
-
2. Java Basics
-
How do we create code?2m 8s
-
Variables and data types4m 6s
-
Strings7m 12s
-
Arrays8m 48s
-
Exploring documentation3m 1s
-
-
3. Control Flow
-
Decision-making with IF5m 37s
-
Comparing loops5m 18s
-
Debugging with an IDE4m 16s
-
Solution: Dice Roll4m 3s
-
4. Beyond the Basics
-
What is encapsulation?6m 40s
-
Working with inheritance9m 12s
-
Interfaces6m 6s
-
Functional programming1m 4s
-
Learning lambda7m 14s
-
Conclusion
-
Next steps37s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: User-defined functions and the this keyword