Hi i just have a question,
i was doing the pass midterm the question is asking that
" Write a class Jacket, which has a boolean instance variable isReversible and a static int variable numJackets. There are no methods "

correct Ans:
public class Jacket {
private boolean isReversible;
private static int numJackets;
}
------------------------
i just wondering for the last one
can i write like :

public static int numJackets;

is that okay ?


Thank you

Yes u can ,
U have to understand the deferents between public and private .
If u made it private this means u can only access from inside the class .But using it as public means u can also access this variable from outside the class .This is a simple explanation .:)

The whole point of declaring something private (which as it was explained means that it is only accessible within the scope of that class) is to prevent the value of the variable changing without supervision. In your case perhaps we would want the number of jackets to lie between 0 and 13 and so when its value is requested to be changed (through a method like setNumberOfJacks(int newNum) then we can control the way numJackets is changed. Of course there are other more relevant reasons for this as well.

Now looking at the solution, as it stands, one would not be able to do anything with the class (unless you inherit) since there are no methods in the class. I'd say both variables should be declared public since the class looks the same as a C++ struct. Though this goes against the purpose of a class - a class is meant to have methods that control its behaviour.

So why did you ask this question anyway? You put public and you got marked down?

Please read the forums rules before posting futher more specialy Keep It Pleasant section

i signed up for a new account just to tell you how anal you are, and then laugh. seriously, relax. maybe some day there will be a language just for forums as to put limitations of things people can say, so they will be more valuable/relative.

insult($username,$lineRefNumber,$statementOfFault,$optionalCommentTowardsMother);

only functions like that wont exist in this language, they will remove anything insulting and possibly even argumentative, generally there will be no means to express your emotion. one day this language will exist, and you will be at rest, until then, continue to scan posts and restrict people's freedom of speech manually.

Comments
signing up just to insult someone you don't know? get a life!
Freedom of speech so you can call other's bad names?! This is not a forum that people to be insulted.
Yeah, bumping a thread nearly 3 years old just to show how smart you are really doesn't cut it

Is is against the forum rules to spam; and any other forum. When you have nothing useful to add or post new information dont post at all.

ProgrammersTalk's post which was quoted in peter_budo's reply was such:

that's just the same thing haha..

What did it contribute to the discussion? How was it helpful for the question that was initially made. It dind't do anything. So posting to a thread to say nothing is against the rules. You may don't know it, but in this forum such as others, there are sometimes people that just make posts that say nothing just for the reason to increase their post counter.

I am not referring to your post, but to the post that had no contribution and resulted in peter_budo's intervantion.

Also your post is a total violation to the rules. And if you start talking about freedom, then when people sign in there are rules to follow. No one is forcing them to sign in and no one is forcing them to stay to this forum. But they have agreed to the rules. So they must follow them.

You critised others without helping anyone. And I am not saying that you are not allowed to express your opinion, I am saying that in this forum, we don't critise others, we help people with their code. I would like to see you do that some time.

This article has been dead for over six months. Start a new discussion instead.