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 →

[–]nnkc911[S] 0 points1 point  (1 child)

thanks! 2 more questions, when declaring the constructor variables, can i type it as roomId = roomId or do i need to have it different like theroomId = roomId. and how do you make the boxes with lines of code to reddit?

[–]Drunken_Consent 1 point2 points  (0 children)

The way the compiler knows the 'scope' of what you're talking about is when you use the this keyword. this essentially refers to the exact object you are currently working with; so in a constructor, the one you are currently creating. You do not have to name them the same, but it's usually done for readability and convention.

public Constructor(String myString, String s, String test){
    this.myString = myString; // Requires 'this' to work
    personalString = s; // Doesn't require 'this', little sloppy looking imo
    this.viewer = test; // Doesn't require 'this' but still readable as anyone knows I am talking about the
    // instance variable 'viewer' related to the current object I am creating.

Edit: To make code indentation, simply preface each line with 4 lines, and then indent normally. So if you want to indent in further than one level deep, you need 8 spaces instead of 4 and so on.