---
title: "Executing a program with several classes"  
description: "Executing a program with several classes"  
author: "Samuel Fernandes"  
published: 2015-04-29  
updated: 2015-04-29  
canonical: https://www.mindstick.com/forum/23156/executing-a-program-with-several-classes  
category: "java"  
tags: ["java"]  
reading_time: 2 minutes  

---

# Executing a program with several classes

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](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) and only had one [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) (main). Now the code has two or more classes. Originally I would [compile](https://www.mindstick.com/forum/2316/how-to-views-compile-in-mvc) the code in the [Command](https://www.mindstick.com/blog/178/synchronous-and-asynchronous-command-execution-in-c-sharp-dot-net) [Window](https://www.mindstick.com/forum/161285/how-does-the-window-console-object-work-in-javascript) by typing "javac" and the [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program)'s name. After it compiled I would [execute](https://www.mindstick.com/interview/49/how-can-i-execute-a-php-script-using-command-line) the program by typing "java -classpath . " and the program's name. However, now when program has several classes I get the following [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing): Could not find or load main class. Below is a program I am having [issues](https://www.mindstick.com/articles/12944/mattresses-for-kids-and-mothers-should-meet-certain-criteria-issues-you-should-consider) with... does it need to be saved as [two separate](https://www.mindstick.com/forum/159375/how-to-communicate-with-two-separate-database-in-mssql-server) 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!");            }        }    }
```

## Replies

### Reply by Anonymous User

Why are you asking if you know the answer already? That is indeed the case.\
They should be in Dog.java and DogTestDrive.java\
\
Then compile and run the class with the main method (DogTestDrive) as you did before.


---

Original Source: https://www.mindstick.com/forum/23156/executing-a-program-with-several-classes

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
