0

Beneath is a pair of classes that I came across in a youtube tutorial. I have come to understand it's functionality almost in its entirety, and I would like to use something similar in a project.
However, I would generally assume that issues would arise if I had multiple instances named Mark..whether it is in the same class file or separate, still in package myClass.

I would like to know if anyone has any ideas on the matter for getting around this, I am fairly new to Java so I would be happy with even a general direction. I have become increasingly more familiar with Java naming conventions over the past couple days but the few articles and videos that I have come across thus far have not yet come to help me understand or workaround this.

In my real world application I am using an ID associated with Mark to name the classes...but so far one would need to do extra work to figure out who's id they are looking at....not a big issue, but an inconvenience. When invoked I could use print or return statements for getName, but this, I think is beside the point...my question is with giving multiple classes/instances similar tags.

Should I stick with the very unique alphanumeric ID as not only the class name but the instance name as well or can i have a 2nd class under a different class name, but with its own unique values in instance Mark?

package myClass
  public class ThisClass{
    public static void main (String[] args){
        Student Mark = new Student();
            Mark.setName("Mark");
     }
}

DIFFERENT CLASS IN PACKAGE myClass;

public class Student{
  String name;
     public String getName(){
            return name;
        }
     public void setName(String name){
            this.name = name;
        }
}
eol
  • 23,236
  • 5
  • 46
  • 64
manYman
  • 1
  • 1
  • _"I would generally assume that issues would arise if I had multiple instances named Mark"_ What issues? Why would they arise? (Making general assumptions isn't always the right thing to do. I just came from a meeting where there was another guy named Ted. We had no issues over that.) – Ted Hopp Dec 02 '16 at 03:22
  • I don't see why not. What problem are you having? Or are you just worrying in the abstract? – Ted Hopp Dec 02 '16 at 03:25
  • what do you mean by "classTwo"?? – J.Baoby Dec 02 '16 at 03:25
  • Are you asking about the scope of your `Mark` variable? Right now it's limited to your `main` method. By the way, variables use camelCase, classes use PascalCase, and contants use SCREAMING_SNAKE_CASE. – 4castle Dec 02 '16 at 03:25
  • If you are talking about the variable/instance name, then you can't have two variables with the same name in the same scope – denvercoder9 Dec 02 '16 at 03:33
  • perfect, thank you guys: Ted Hopp, J.Baoby, 4castle, Rafiduzzman Sonnet, i got my answer plus some!!:) – manYman Dec 02 '16 at 03:47

0 Answers0