Just Teaching Myself Java--Trivial Problem
Hi All:
I'm a VB user. I'm planning to write a research simulation in Java over this summer because it is a better web development language. Iv'e got my GUI started and I want to call a class called Driver from Main:
Here is the entire class Driver
public class Driver {
System.out.println ("ABC");
}
I'm getting an error-- "misplaced constructs"
What is wrong with this trivial code.
Re: Just Teaching Myself Java--Trivial Problem
I moved this thread, please don't post questions in the Member Introductions forum. Please read this: http://www.javaprogrammingforums.com...e-posting.html
The code doesn't make sense, because you can't have a statement like that outside of a method or a constructor. When would that code ever be called?
Re: Just Teaching Myself Java--Trivial Problem
That System.out.println("ABC"); call is sitting out in the middle of nowhere. You need to give it either a method or a constructor to be inside. To do that, just create a constructor for Driver, and then put the call inside the constructor.
The only thing you can do outside of methods and constructors (as far as I know) is create variables.
Re: Just Teaching Myself Java--Trivial Problem
Seeing that you are crossing over from VB and considering you already have a GUI set up, I'm surprised that you are having a problem with something this fundamental. Did you perhaps use a WYSIWYG gui generator? Anyway, I suggest you start here: The Java™ Tutorials
Specifically in the Trails Covering the Basics section.
Re: Just Teaching Myself Java--Trivial Problem
Re: Just Teaching Myself Java--Trivial Problem
You cant start a statement without a constructor.
Re: Just Teaching Myself Java--Trivial Problem
You don't have a constructor nor any methods. You need to put it inside either a constructor or a method.
Preferably a constructor if that's the entire class.
Not sure what you mean by "statement"
You can have a class with nothing in it except a class declaration (which is what you have right now, except you have something else in it.)
This is a constructor:
public Driver()
{
}
As for a "statement"
This is a valid statement;
int i = 5;