Ask coding questions

← Back to all posts
1
Accessing object arguments from main
Jajanina (0)

Hello. So I created a "Super" class with a no-argument constructor as well as one that takes a list of string arguments. One of them is "alias". I made it private and created getters and setters all in the "Super" class. I then created an "XMen" class that extends the "Super"class and created a "wolverine" object (and a few more) and passed the string alias argument, "Logan" into. I am now in main attempting to access wolverine's alias, but I am getting the alias of the last Super object that I created in the XMen class instead of getting wolverine's alias.

Now, getAlias() returns the correct alias when I use setAlias() , but shouldn't getAlias() return the correct alias since I passed in the alias argument into my wolverine object?

I just don't understand why XMen.wolverine.getAlias() is returning the last "Super" object in the XMen class and not wolverine's.

Thanks!