0

I have the following code, that i have revised multiple times:

public class double3 {
    public double x=0;
    public double y=0;
    public double z=0;
    public double3(double a, double b, double c){
        this.x=a;
        this.y=b;
        this.z=c;
    }
}


double3[] samples = new double3[4];//syntax error on token ";", { expected after this token
samples[0]=new double3(1,2,3);

What is happening here and what is eclipse trying to say to me?

1 Answer 1

2

The statements

double3[] samples = new double3[4];
samples[0] = new double3(1,2,3);

should be in a code block such as a method, constructor or instance initializer

Sign up to request clarification or add additional context in comments.

8 Comments

Right, because Java is unlike scripting languages such as Javascript that allow for arbitrary execution of code outside of methods. A main method is needed to kickstart the process.
Yes! Dumb error of me. It was actually inside a bigger and lengthy class, and my previous C experience doesn't warn me about this things. Thank you! (I will accept when allowed to)
Note that Java classes start with an uppercase letter, e.g. Double3 - read more here
Actually its the statement: samples[0] = .... It expects to find it in a code block so its expecting the brace {
It doesn't expect it after the semicolon, it expects a brace before the semicolon but gets the semicolon first and chokes.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.