Java Object Declaration Error Question!

Asked 1 years ago, Updated 1 years ago, 363 views

Hello, I'm asking you a question because I'm stuck in an object declaration error while studying Java!

#Box.java
public class Box {
    int width=0;
    int height=0;

    public void printSize()
    {
        System.out.println("Size: "+(width*height));
    }
}
#BoxTest.java
public class BoxTest {
    public static void main(String[] args) {
        Box mybox = new Box();
        mybox.width=30;
        mybox.height=20;
        mybox.printSize();
    }
}

C:\java1> javac Box.java BoxTest.java
C:\java1> java BoxTest.java

If it is as stated in the book, it should be executed normally when this is done.

#Error

C:\java1> java BoxTest.java

BoxTest.java:3: error: cannot find symbol

        Box mybox = new Box();


  symbol:   class Box

  location: class BoxTest

BoxTest.java:3: error: cannot find symbol

        Box mybox = new Box();

  symbol:   class Box

  location: class BoxTest

2 errors

error: compilation failed

An error appears stating that the class box is incorrect

It is said that cannot find symbol is usually a typo problem, but I don't think it is.

I have a question

Any help would be appreciated!

java javac

2023-03-19 20:09

1 Answers

javaThe command runs a compiled class file or archive file.

java BoxTest

You must enter .


2023-03-21 01:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.