Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App (2014) Basic Android Programming Generating a Random Number

Varun Singh
Varun Singh
1,905 Points

Classes and Objects, same or different ?

I understand thoroughly about the class and new instance often addressed as object of that class. But my question is why it is written as :- OBJECTS> String, Random, Activity and TextView when they all are classes. String, Random and Activity are objects or are they also called classes ? if Yes, then why ?

Confused ?????

4 Answers

To make it simple and easy to understand. I will put down a real life example of objects classes and method.

Dog is an object, Breed is a class, and Barking is a method.

So every object has class and method.

Basically, a class is a blueprint for objects.

So for example if you have a class you have made called vegetable you can instantiate it (create an instance of it) and use it's various different functions and methods.

I hope this was helpful. Feel free to ask any more questions.

-Luke

Varun Singh
Varun Singh
1,905 Points

no luke. still not getting it. i am sorry but thanks for your effort

Hmm, what do you not understand Varun?

Varun Singh
Varun Singh
1,905 Points

I was writing a code for random number generation designed by Ben. The code is below:-

Random randomGenerator = new Random(); // Random is a class and a new instance is made

but there is a Presentation chart, which says : Random, String and Activity are objects

Confused ?????

Random, String and Activity are actually all classes but you can create a new instance of these classes and that instance is known as an object!

Random randomGen = new Random();

Random is the class and the new instance of that class (or the object) is called randomGen.

Varun Singh
Varun Singh
1,905 Points

I understand thoroughly the class and new instance often addressed as object of that class. But my question is why it is written as :-------> OBJECTS> String, Random, Activity and TextView when they all are classes.