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 trialVarun Singh
1,905 PointsClasses 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
a ak47
3,944 PointsTo 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.
Luke Glazebrook
13,564 PointsBasically, 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
1,905 Pointsno luke. still not getting it. i am sorry but thanks for your effort
Luke Glazebrook
13,564 PointsHmm, what do you not understand Varun?
Varun Singh
1,905 PointsI 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 ?????
Luke Glazebrook
13,564 PointsRandom, 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
1,905 PointsI 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.