The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

an exercise from EBook "TIJ 2/e"

Posted by Steve on April 11, 2000 at 7:52 PM

I was referred from Bruce Eckel's site "Thinking in Java 2nd ed."

Chapter 2: Everything is an object - exercise 2 says, "Find the
code fragments involving ATypeName and turn them into a program
that compiles and runs."
The code fragments are: "class ATypeName2 {}" and
"ATypeName a = new ATypeName();"

I did get it to compile and run with:
class ATypeName2 {
public static void main(String[] args) {
ATypeName a = new ATypeName();
System.out.println(a);
}
}

//OutPut was: ATypeName@774a07df

...even though this is probally not what Mr. Eckel meant. But I
did not fare well with my original code:
class ATypeName {
public static void main(String[] args) {
ATypeName a = new ATypeName("Wow");
System.out.println(a);
}
}

//OutPut: ATypeName2.java:4: Wrong number of arguments in constructor.
// ATypeName a = new ATypeName("Wow");
// ^
// 1 error

Could someone who is familiar with "TIJ" please go through
the second code and explain in laymans terms the error and what
I'm doing wrong? I think () is the constructor? Maybe even a few
solutions to the exercise. I know this is an easy problem - I'm
keeping an eye out for Thinking in Java (Sped version) LOL

Thanks, Steve




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us