Java Programming: 9 – Classes and Objects

In this tutorial we learn how to instantiate objects from classes that we create. We learn about instance variables, instance methods, and constructors. Getters and setters are introduced and encouraged as good coding practice.

The static modifier is also explained.

You would usually make instance variables private when public getters/setters are provided as part of the interface, but access modifiers have not yet been covered in this series.

You can also move the main method to the Person class and keep the program for this tutorial in one file, however, I thought it would better get the concept across by having the Person class be isolated from main.


EvlutnTrnrDaisy says:

I’m trying to do this same thing on Netbeans 7.2. Does it matter that I’m using a different compiler than you? When I tried to pass in String name to the public Person(){ } it kept saying it was wrong. I followed your example exactly and I can’t get this part to work. Please help!

Brownkevin7 says:

Thank you , found this so confusing for some reason and in the first minute you explain its use and why we do it which is all i needed to hear. My professor gave me some long convoluted explanation when all he had to say was the four sentences you said

TheManeOfLife says:

What if you want to player to move

EIDnext Week says:

thank you

Danielle Romanoff says:

Great video and very clear explanation. Thank you!

GUrpreet Singh says:

you deserve billion subscriber sir.

The gamer says:

for example I want to create an app

.. I can write it’s code in one class or many class ??… .
and what the difference between the coding in one class or many classes ?

Jennifer Lam says:

Thank youuu so much!!

nakiew says:

Helped me a whole lot, thanks.

The gamer says:

in.. puplic person ( string name)

string name refer to what?

jonbar87 says:

Best Java tutorials on Youtube. Thank you!

Oscar Healy says:

very helpful thanks :]

Keith Ford says:

this is so good. thank you.

The gamer says:

new person … this person is an object or class

eiloolie says:

You are very talented at getting information across. You speak clearly, slowly and you are precise.

Thanks a lot.


myp410up says:

EXCELLENT tutorial! Thank you SO much for posting these informative, concise and extremely helpful instructional videos. I have been reading up on Java for a few weeks now but seeing it in action with your code examples really ties all the concepts together in my mind. Thank you!

I wanted to ask a quick question. In one of the books I read which talked about coding getters and setters for a class, it advised to make the variables private so that the only way to access them is through the getter/setter methods. That way you can validate input values and control access to instance variables since you are not able to directly access private variables from another class. In this case, then, shouldn’t the name and age variable be converted from their default public access to private? Thanks a lot.

Stettafire says:

Thank you this was helpful, although I’m still trying to figure out how to have an object where one of the variables inside it is equal to the input made by the user. I will work it out though, I am nothing if not determined.

Ricky O' Callaghan says:

Great video, very well explained.

penyou says:

Is instance same as object?

johan banan says:

a million thumbs up !

Takunda Mutombodzi says:

really nice tutorial man

TheCoffeeCrafter says:

I’m new at programming in Java and this video has been so helpful! Thanks so much!

ostad plus says:

man its for beginners why did you used of swing ? i cant blieve

Žan R says:

For those of you who can’t grasp the concept of objects and classes. I was in the same situation as you. I watched a ton of videos and I just didn’t quite get it. So after hours of researching about objects and classes I finally decided that I would actually write the code that these Youtubers were writing in their tutorials. I did some examples after these kind of tutorials and I basically practiced what they were doing. I also googled some exercises for this topic and after a couple of hours everything started making sense. The point is don’t just watch these tutorial videos. You should try to write the code by yourself and do exercises that way you can really start thinking and overtime you will start understanding what they were talking about. Trust me.

Pascal Vautour says:

Omg i fucking love you, 20 minutes before the due date and you just saved my ass ! xD

Juandre van der Westhuizen says:

Thanx bro, I had a problem with understanding how OOP works but you made it so simple

bnntl312 says:

I am actually getting this..Nice and easy to follow. Many thanks

TrollBronze says:


William J says:

so when a method inside a class is labeled “static” it effects all the objects?

Tan Lee Lee says:


Sjoerd Flameling says:

Ive just watched one video and I’m already subscribed

Write a comment


Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.

Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles▷ Show Cars▷ Motorbikes▷ Scooters▷ Bicycles▷ Rims & Tires▷ Luxury BoatsFashion▷ Sunglasses▷ Luxury Watches▷ Luxury Purses▷ Jeans Wear▷ High Heels▷ Kinis Swimwear▷ Perfumes▷ Jewellery▷ Cosmetics▷ Shaving Helpers▷ Fashion HatsFooding▷ Chef Club▷ Fooding Helpers▷ Coktails & LiquorsSports▷ Sport Shoes▷ Fitness & Detox▷ Golf Gear▷ Racquets▷ Hiking & Trek Gear▷ Diving Equipment▷ Ski Gear▷ Snowboards▷ Surf Boards▷ Rollers & SkatesEntertainment▷ DIY Guides▷ Zik Instruments▷ Published Books▷ Music Albums▷ Cine Movies▷ Trading Helpers▷ Make Money▷ Fishing Equipment▷ Paintball Supplies▷ Trading Card Games▷ Telescopes▷ Knives▷ VapesHigh Tech▷ Flat Screens▷ Tech Devices▷ Camera Lenses▷ Audio HiFi▷ Printers▷ USB Devices▷ PC Hardware▷ Network Gear▷ Cloud Servers▷ Software Helpers▷ Programmer Helpers▷ Mobile Apps▷ Hearing AidsHome▷ Home Furniture▷ Home Appliances▷ Tools Workshop▷ Beddings▷ Floor Layings▷ Barbecues▷ Aquarium Gear▷ Safe Boxes▷ Office Supplies▷ Security Locks▷ Cleaning ProductsKids▷ Baby Strollers▷ Child Car Seats▷ Remote ControlledTravel▷ Luggages & Bags▷ Airlines Seats▷ Hotel Rooms▷ Fun Trips▷ Cruise Ships▷ Mexico Tours