0

GreetingsClass.java Chapter1.java Chapter2.java Chapter3.java

I have one class, GreetingsClass.java, in package com.CITC1318.course;. Three other classes, Chapter1.java, Chapter2.java, Chapter3.java, in package com.CITC1318.course.Chapters;. GreetingsClass.java imports and creates an object of the other 3 classes. Each constructor in the Chapter classes prints "Hello from Chapter1!", "Hello from Chapter2!", "Hello from Chapter3!" -respectively. The output of GreetingsClass.java should read-

$ Greetings, CITC1318!

Hello from Chapter1!

Hello from Chapter2!

Hello from Chapter3!

But I keep getting this...

1 Answers1

0

When you are constructing your Object you are printing them out, and then after all three Objects are printing out, you are then trying to print the Objects again, but as the Classes do not implement a toString method, you will get something like chapter2@1230123

Remove the S.O.P from your calling class.

Just instantiate the Objects.

Scary Wombat
  • 44,617
  • 6
  • 35
  • 64