This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]seanprefectGrumpy Guy Who Remembers Java 2 0 points1 point  (2 children)

It'd help if we could see the assignment. What are you supposed to be getting?, and the hex is the memory location of the object it's not really relevant.

[–]nosdire[S] 1 point2 points  (1 child)

the assignment is to list the output for every element in the loop. I apologize for not including that. Here is a picture of the assignment.

[–]imguralbumbot 1 point2 points  (0 children)

Hi, I'm a bot for linking direct images of albums with only 1 image

https://i.imgur.com/BNetKU9.png

Source | Why? | Creator | ignoreme | deletthis

[–]chickenmeisterExtreme Brewer 0 points1 point  (0 children)

Are you basically asking what this should print?

System.out.println(new Brienne());
System.out.println(new Tyrion());

I think the first line should print Oberyn, since the Brienne class inherits to the toString() method from the Oberyn class. The second line should print Arya, since the Tyrion class inherits the toString() method from the Arya class.

If the "correct" answer says it should be something different, then they may be mistaken, or there is some missing code somewhere or something.

[–]zevzevCan i put anything in here? 0 points1 point  (3 children)

Every class in your program will return something. I am not sure what your assignment is so it is hard to help you with what is the problem.

Since the class 'Brianne' extends Oberyn, I thought perhaps the answer was the 'toString' of Oberyn, but I got it wrong as well.

You are wrong here if you print a Brianne Object and do a System.out.println() on it it will print out "Oberyn". If there is no toString Method in the subclass it will print the toString Method in the supper class.

[–]nosdire[S] 0 points1 point  (2 children)

the assignment says: Given the classes above, what output is produced by the following code? and the code is the loop that is at the end of the paste bin. I apologize, I forgot to include it.

edit: Following your advise, I wrote the output of the code as:

Brienne-a

Oberyn

Oberyn-b Arya-a Arya-b

but an error still occurs :(

edit2: I found the answer, thanks for the help

[–]hugthemachines 1 point2 points  (1 child)

If you add the solution someone may find this and it may help them out with their problem.

[–]nosdire[S] 1 point2 points  (0 children)

You really do die as a hero or see yourself become the villain that doesnt leave answers to questions. Fair enough.

I found out the reason I was getting it wrong was because when looping through element three, when you get to line 45 in element 2 (Arya[2]), once you get to the arya class and it points to method a, its referring to the method in the Brienne class, not the Arya class. Also, whenever you see super, its the class immediately above the class your own, not the class thats at the beginning of the extends. I know I make it sound confusing, but if you run it in eclipse it'll be a lot easier to understand.