forum

Home / DeveloperSection / Forums / Executing a program with several classes

Executing a program with several classes

Samuel Fernandes 1553 29-Apr-2015
I am working my way through "Head First Java" and typing the code in the book into Notepad++ as I go. In the first few chapters the code was simple and only had one class (main). Now the code has two or more classes. Originally I would compile the code in the Command Window by typing "javac" and the program's name. After it compiled I would execute the program by typing "java -classpath . " and the program's name. However, now when program has several classes I get the following error: Could not find or load main class. Below is a program I am having issues with... does it need to be saved as two separate files? 
class DogTestDrive {
     
    public static void main (String [] args) {
        Dog one = new Dog();
        one.size = 70;
        Dog two = new Dog();
        two.size = 8;
        Dog three = new Dog();
        three.size = 35;
         
        one.bark();
        two.bark();
        three.bark();
    }
}
class Dog{
 
    int size;
    String name;
     
    void bark() {
        if (size > 60) {
            System.out.println("Woof! Woof!");
            } else if (size > 14) {
            System.out.println("Ruff! Ruff!");
            } else {
            System.out.println("Yip! Yip!");
            }
        }
    }

Updated on 29-Apr-2015

Can you answer this question?


Answer

1 Answers

Liked By