This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Compiling multiple source files. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Compiling multiple source files." Watch "Compiling multiple source files." New topic
Author

Compiling multiple source files.

Chidimma Juliana
Greenhorn

Joined: Jul 14, 2011
Posts: 18
Hello,

I have been trying to compile two source files from a command line using the examples on K & B SCJP study guide. Am using Window Vista and my compiler(JDK) is working properly.

Please, could someone explain to me how to compile these two programs from a command line;

class GameShape{
public void displayshape(){
System.out.println("displaying shape");
}
}

class PlayerPiece extends Gameshape{
public void movePiece(){
System.out.println("moving game piece");

AND

public class TestShapes{
public static void main(String[] args){
PlayerPiece player = new PlayerPiece();
TilePiece title = new TilePiece();
doshapes(player);
doshapes(tile);
}
public static void doshapes(GameShape shape){
shape.displayShape();
}

}

}
}

class TilePiece extends GameShape{
public void getAdjacent(){
System.out.println("getting adjacent tiles");
}
}

Your response is highly needed
Thank you.
Ogeh Ikem
Ranch Hand

Joined: May 13, 2002
Posts: 180
Welcome to the ranch

Try this:

Chidimma Juliana
Greenhorn

Joined: Jul 14, 2011
Posts: 18
Actually I have compiled some other class and it was successful.

But in this situation, I have two programs saved in two different files,

GameShape.java file contains:
class GameShape{
public void displayShape(){
System.out.println("displaying shape");
}
}

class PlayerPiece extends GameShape{
public void movePiece(){
System.out.println("moving game piece");

}
}

class TilePiece extends GameShape{
public void getAdjacent(){
System.out.println("getting adjacent tiles");
}
}


AND

TestShapes.java files contains:

public class TestShapes{
public static void main(String[] args){
PlayerPiece player = new PlayerPiece();
TilePiece title = new TilePiece();
doShapes(player);
doShapes(title);
}
public static void doShapes(GameShape shape){
shape.displayShape();
}

}

Error messages from the compiler;

C:\Users\Chidimma>cd C:\Documents and Settings\Chidimma\Desktop\Allfiles

C:\Documents and Settings\Chidimma\Desktop\Allfiles>javac TestShapes.java
.\GameShape.java:7: cannot find symbol
symbol: class Gameshape
class PlayerPiece extends Gameshape{
^
TestShapes.java:7: doshapes(GameShape) in TestShapes cannot be applied to (Playe
rPiece)
doshapes(player);
^
TestShapes.java:8: cannot find symbol
symbol : variable tile
location: class TestShapes
doshapes(tile);
^
TestShapes.java:11: cannot find symbol
symbol : method displayShape()
location: class GameShape
shape.displayShape();
^
4 errors

C:\Documents and Settings\Chidimma\Desktop\Allfiles>

Thank you.

Ogeh Ikem
Ranch Hand

Joined: May 13, 2002
Posts: 180
Hello Chidimma. Please use the code button to paste your code.
Ogeh Ikem
Ranch Hand

Joined: May 13, 2002
Posts: 180
You have spelling errors in your classes. For example

PlayerPiece extends Gameshape

should be

PlayerPiece extends GameShape

Also, in the TestShapes class

doshapes(tile);

should be

doshapes(title);
Chidimma Juliana
Greenhorn

Joined: Jul 14, 2011
Posts: 18
Hello Ogeh,

Thank you so much. After correcting the errors, the program compiled and executed.

Ogeh Ikem
Ranch Hand

Joined: May 13, 2002
Posts: 180
You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compiling multiple source files.
 
Similar Threads
please solve my query
Class Casting
K&B book code example question..
error pg 89 of K&b 5.0 study guide
i don't get to know why this program cannot be executed?