Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Perfecting the Prototype Parsing Integers

Chris Janowski
Chris Janowski
1,844 Points

What is a class?

I'm sure this is a dumb question and I apologize for that, but I just want to make sure I understand all the language terms.

myName: Variable String and int: Data types console.readLine: Method console: Object

What exactly is a class?

5 Answers

Mohsin Ayub
Mohsin Ayub
6,822 Points

A class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions, methods). As you just said that console: Object. So this console object is the instance of Java Standard Library Class Console. This class also contains the method readLine(). The object is already created by the instructor. The instructor set the name of the object to console so after creating the object you can access the public data members and methods of that class.

Tobias Edwards
Tobias Edwards
14,458 Points

Might as well have a crack at it!

A class in Java is essential to the language, without it the code won't run (I think). A class is like a kitchen, and inside the kitchen is where you make the food. A class contains methods (functions inside classes), which are like the things you use to make the food.

Chris Janowski
Chris Janowski
1,844 Points

Thank you for answering and using a metaphor, it made it very easy to understand.

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

I find it easiest to think of it as a blueprint used to create objects.

Class is set Of Methods and Data Member like variables int,string etc.

Chris Janowski
Chris Janowski
1,844 Points

Is a class what stores the methods?

Tobias Edwards
Tobias Edwards
14,458 Points

A 'method' is just another word for: a function inside a class.

Very good answers!