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.…
- Downloading Java 9 and choosing an IDE
- Understanding Java basics: data types, strings, arrays, and more
- Controlling flow with functions and loops
- Working with inheritance and interfaces
- Learning lambda
Skill Level Beginner
1. Getting Started
2. Java Basics
3. Control Flow
4. Beyond the Basics
- 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.Cancel
Take 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.