Quantcast
Channel: Variables in Constructor? - Stack Overflow
Browsing all 5 articles
Browse latest View live

Answer by SimplyPanda for Variables in Constructor?

Because you declare word in the constructor, ie the text:String word = "p u m p k i n";String blanks = "_ _ _ _ _ _ _";is within the brackets of public Hangman(), it is local to the constructor. It...

View Article



Answer by Rahul for Variables in Constructor?

Declare them as instance variables and initialize them in the Constructor. If you declare and initialize them in the constructor, they'll will be accessible only within the constructor(local scope) and...

View Article

Answer by Aniket Thakur for Variables in Constructor?

You have to do the followingpublic class Hangman{private String word;private String blankspublic Hangman () { word = "p u m p k i n"; blanks = "_ _ _ _ _ _ _";} int k = word.length(); ... rest code...

View Article

Answer by Suresh Atta for Variables in Constructor?

Each time you are creating the local variables in constructor.public Hangman () { String word = "p u m p k i n"; String blanks = "_ _ _ _ _ _ _";}What you have to do is Assign values in constructor to...

View Article

Variables in Constructor?

I am currently a beginner in Java programming and was tasked to "Code and test a version of the Hangman game. Your solution will involve a Hangman class whose constructor chooses a word, and whose...

View Article

Browsing all 5 articles
Browse latest View live


Latest Images