+ 9

Classes. I understand the concept but i didn't quite grasp it....

Can someone please explain to me what exactly it is and how it works? Thanks Appreciate it!!!😀

17th Dec 2016, 6:18 PM
Ndkc
Ndkc - avatar
11 Réponses
+ 14
A class allows you to make a object with a new data type. This object contains certain data and does certainly behaviors. For example, you could make a Card class to make card games. It would have fields for the card's Value and its Suit. It would have behaviors to retrieve its value and its suit. Every Card object is separate from one another. You could have one that's a 7 of Clubs, and another that's a 4 of Hearts. You could make enough Card objects for a whole Deck. So in a Deck class, you could have an array of 52 Card objects. And you could have methods to initialize the Deck, or shuffle it, or deal out 5 random Cards, or something of that nature. This Deck could be used for a Game, with a score, players, money, etc. Basically, it's a very natural way of structuring a program, thinking of the separate pieces/classes you'll need and mapping out how they behave and interact.
17th Dec 2016, 8:23 PM
Tamra
Tamra - avatar
+ 9
You create a class let say Fruit, where you specify that it has a color and taste. Than you can create an object of that class by using the new keyword i.e: apple, orange...
18th Dec 2016, 9:32 AM
Klodian Lula
Klodian Lula - avatar
+ 7
The example here are...not very good at explaining how classes and objects are useful, just the syntax to make and use them. It trips people up a lot.
17th Dec 2016, 9:01 PM
Tamra
Tamra - avatar
+ 5
Oh. ._. Lots of people don't really get why they're a thing so that's my fault.
17th Dec 2016, 8:49 PM
Tamra
Tamra - avatar
+ 4
Class is the derived data type which is used to create variable of that data type class->data type variable-> Object asume it hope you understand
20th Dec 2016, 2:43 PM
Riyaz Sheikh
Riyaz Sheikh - avatar
+ 3
Just to add, classes encourage encapsulation and define a structure by which we can have interrelated classes, divide and conquer by having a class as a functional unit that then can be subclassed or if it's an interface, defines strict ways in which you can use the interface either way it's all about divide and conquer
19th Dec 2016, 4:14 PM
Eric Gitangu
Eric Gitangu - avatar
+ 3
Class - Let's consider an example consider "Dog" what he can do bark(),eat(),sleep() <- these r the things he can do so these are methods.Now talk about his colour,shape,breed <- these are attributes we had put these methods and attributes in a single box called class that is dog which means class is a collection of similar kind of objects & object if a class is just a remote of T.V u have to press the button then your channel is going to change similarly if dog object is 'ob' so to make our dog bark we will use ob.bark(); I hope u understand👍
20th Dec 2016, 4:40 AM
Ankur Suhane
Ankur Suhane - avatar
+ 2
By default your programming language just knows the primitive data types: int,float, char, double, boolean etc. But it does not know what a Room, Person, Bag, Chair, Furniture, Face, Bed, Game, Snake, House, Animal is. So the concept of class was introduced to give you the ability to define these unknown things using the primitive data types above so that your code can now be understood by the compiler!
19th Dec 2016, 2:52 PM
Caffeinated Gamer YT
Caffeinated Gamer YT - avatar
+ 1
a project it's formed by a lot of class, so when you run the code it runs all the classes and you can do more classes and not write a code very long
20th Dec 2016, 5:27 PM
Mars
Mars - avatar
0
Thanks I understood that before. What's troubling me is how that works in code (mainly java). My bad, my question wasn't clear enough
17th Dec 2016, 8:37 PM
Ndkc
Ndkc - avatar
0
what do you mean???
17th Dec 2016, 8:52 PM
Ndkc
Ndkc - avatar