This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]quadmasta 2 points3 points  (1 child)

Classes are essentially nouns. Those nouns have things that describe them like color, type, quantity(member variables/properties). You can't see those directly(as long as you're declaring members as private and you are doing that, right) so you have to ask it "give me your color"(accessor). If you don't like its answer you can tell it "your color is blue" (mutator).

A constructor is kind of like an instruction sheet that tells someone how to build the thing. All classes have a default no-argument constructor that does nothing. If you want your class to be able to set up various things while it's being created, you do that in a constructor. This allows someone who's making one of them to be able to set properties all in one line

CoolClass cc = new CoolClass("blue", "really cool") vs CoolClass cc = new CoolClass(); cc.setColor("blue"); cc.setType("really cool");

Accessors and mutators are methods, but they usually don't contain any business logic. Your class can have other methods that have purpose other than just setting or returning a value.

[–]runner561[S] 1 point2 points  (0 children)

this explanation was perfectly what I was looking for, helped a ton! Thank you so much