Introduction:
In this exercise, you are going to exercise the concept of overloading, Please note that overloading and overriding are two different concepts.
Steps to follow:
1. Modify StudentRecord.java of Exercise 10.1 as shown in Code-10.2.a below. The code fragement that needs to be added is highlighted with bold and blue-colored font.
* Add two overloaded print(..) methods.
public class StudentRecord {
...
public void print(String name ){
System.out.println("Name:"+name);
}
public void print(String name, double averageGrade){
System.out.print("Name:"+name+" ");
System.out.println("Average Grade:"+averageGrade);
}
}
Code-10.2.a: StudentRecord.java
2.Write StudentRecordExample2.java as shown in Code-10.2.b below.
* cd \myjavaprograms (if you are not in this directory already)
* jedit StudentRecordExample2.java
public class StudentRecordExample2{
public static void main(String [] args) {
StudentRecord annaRecord =new StudentRecord();
annaRecord.setName("Anna");
annaRecord.setEnglishGrade(95.5);
annaRecord.setScienceGrade(100);
// Invoke overloaded methods
annaRecord.print(annaRecord.getName());
annaRecord.print(annaRecord.getName(), annaRecord.getAverage());
}
}
Code-10.2.b: StudentRecordExample2.java
3. Compile and run the code. If you experience compile errors, fix the compile errors.
* javac *.java (or javac StudentRecord.java StudentRecordExample2.java)
* java -classpath . StudentRecordExample2
4. Verify the result
* Name:Anna
Name:Anna Average Grade:65.16666666666667
Steps to follow if you are using NetBeans
It is assumed you are using the same NetBeans project you created in Exercise 10.1.
1. Modify the StudentRecord.java of Exercise 10.1 as shown in Code-10.2.a above
2. Write StudentRecordExample2.java
* Right studentrecordexample package node (Not StudentRecordExample project node) and select New->Java Class
* Under Name and Location pane,
o for Class Name field, type StudentRecordExamle2
o Click Finish
3. Modify the NetBeans generated StudentRecordExample2.java
* Replace the code of the NetBeans generated StudentRecordExample2.java with the one of Code-10.2.b above while leaving the package statement at the top
4. Right click studentrecordexample package node (Not StudentRecordExample project node) and select Compile Package (F9)
5. Right click StudentRecordExamle2 and select Run File
Homework:
1. Modify StudentRecord.java as following
* Add another overloaded print() method which takes the following three parameters
o name
o grade average
o student count
2. Modify StudentRecordExmaple2.java as following
* Invoke the newly added print() method
Popular Posts
-
5.3 Draw.aspx Web Applications I am just about to finish this tutorial. I have given you a couple of code samples to chew on, but t...
-
SQL Management Studio comes in two flavours: 1. SQL Management Studio This edition comes with all versions of SQL Server 2005 except SQL Ser...
-
5.1 The .NET Framework: Big Picture Figure 5‑1 The .NET Framework in Context Looking at Figure 5‑1 we see the lifespan of managed c...
-
2.1 Intermediate Language, Metadata and JIT Compilation Managed code is not interpreted by the CLR. I mentioned that earlier. But ...
-
4.3 Using the FCL “Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.” The IO strea...
-
Learning about Events (Continue) Lets program the Form_Load event. "MsgBox" is Visual Basic command that launch a message box. for...
-
Data Adapter Configuration Wizard Generating DataSet To create a DataSet, select Data->Generate DataSet from the main menu. From the dial...
-
1.1 Code in a Highly Distributed World Software that addresses the Internet must be able to communicate. However, the Internet is n...
-
4.2 The Framework Class Library Now that you have a taste of the goals and groundwork laid by the CLR and managed code, let’s taste ...
-
A JSP expression is used to insert Java values directly into the output. It has the following form: The Java expression is evaluated, conver...
Monday, February 23, 2009
Exercise 10.3: Classpath again at the command line
Please do this exercise at the command line instead of using NetBeans. This is to learn the concept of classpath without the help of NetBeans.
Introduction:
I hope you have a reasonably good understanding on classpath. Since classpath is a very important concept, we are revisiting it here. The goal of this exercise is that even the javac compiler depends on the classpath.
Steps to follow:
1. If you have used NetBeans to do the exercise 10.2 above, please create StudentRecord.java and StudenRecordExample.java as shown in Code-10.1.a and Code-10.1.b below using your editor of choice at the command line. Please note that StudentRecordExample class uses StudentRecord class.
* set CLASSPATH= (in order not to depend on the classpath environment variable just for this exercise)
* cd \myjavaprograms
* jedit StudentRecord.java (using code Code-10.1.a above)
* jedit StudentRecordExample.java (using code Code-10.1.b above)
2. Compile code using the following method. The compilation should succeed.
* javac StudentRecord.java StudentRecordExample.java
3. Compile code individually as following.
* javac StudentRecord.java
* javac StudentRecordExample.java
4. The compilation of the StudentRecord.java should succeed but the compilation of StudentRecordExample.java should fail as following:
* C:\myjavaprograms>javac StudentRecord.java
C:\myjavaprograms>javac StudentRecordExample.java
StudentRecordExample.java:6: cannot find symbol
symbol : class StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord annaRecord =new StudentRecord();
^
StudentRecordExample.java:6: cannot find symbol
symbol : class StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord annaRecord =new StudentRecord();
^
StudentRecordExample.java:9: cannot find symbol
symbol : variable StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord.increaseStudentCount();
^
StudentRecordExample.java:12: cannot find symbol
symbol : class StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord beahRecord =new StudentRecord();
^
StudentRecordExample.java:12: cannot find symbol
symbol : class StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord beahRecord =new StudentRecord();
^
StudentRecordExample.java:15: cannot find symbol
symbol : variable StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord.increaseStudentCount();
^
StudentRecordExample.java:18: cannot find symbol
symbol : class StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord crisRecord =new StudentRecord();
^
StudentRecordExample.java:18: cannot find symbol
symbol : class StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord crisRecord =new StudentRecord();
^
StudentRecordExample.java:21: cannot find symbol
symbol : variable StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord.increaseStudentCount();
^
StudentRecordExample.java:32: cannot find symbol
symbol : variable StudentRecord
location: class studentpackage.StudentRecordExample
System.out.println("Count="+StudentRecord.getStudentCount());
^
10 errors
The compile error occurs because StudentRecordExample class uses StudentRecord class and the javac compiler could not find the StudentRecord class in the default classpath. Since you did not specify the "-classpath" option when you compile the code, the javac compiler takes either CLASSPATH environment variable if it has been or no classpath. This is in a sense the same problem as you might have seen in Exercise 3.1.
5. Specify the classpath for compilation as well. Now the compilation of both files should succeed.
* javac StudentRecord.java
* javac -classpath . StudentRecordExample.java
Introduction:
I hope you have a reasonably good understanding on classpath. Since classpath is a very important concept, we are revisiting it here. The goal of this exercise is that even the javac compiler depends on the classpath.
Steps to follow:
1. If you have used NetBeans to do the exercise 10.2 above, please create StudentRecord.java and StudenRecordExample.java as shown in Code-10.1.a and Code-10.1.b below using your editor of choice at the command line. Please note that StudentRecordExample class uses StudentRecord class.
* set CLASSPATH= (in order not to depend on the classpath environment variable just for this exercise)
* cd \myjavaprograms
* jedit StudentRecord.java (using code Code-10.1.a above)
* jedit StudentRecordExample.java (using code Code-10.1.b above)
2. Compile code using the following method. The compilation should succeed.
* javac StudentRecord.java StudentRecordExample.java
3. Compile code individually as following.
* javac StudentRecord.java
* javac StudentRecordExample.java
4. The compilation of the StudentRecord.java should succeed but the compilation of StudentRecordExample.java should fail as following:
* C:\myjavaprograms>javac StudentRecord.java
C:\myjavaprograms>javac StudentRecordExample.java
StudentRecordExample.java:6: cannot find symbol
symbol : class StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord annaRecord =new StudentRecord();
^
StudentRecordExample.java:6: cannot find symbol
symbol : class StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord annaRecord =new StudentRecord();
^
StudentRecordExample.java:9: cannot find symbol
symbol : variable StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord.increaseStudentCount();
^
StudentRecordExample.java:12: cannot find symbol
symbol : class StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord beahRecord =new StudentRecord();
^
StudentRecordExample.java:12: cannot find symbol
symbol : class StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord beahRecord =new StudentRecord();
^
StudentRecordExample.java:15: cannot find symbol
symbol : variable StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord.increaseStudentCount();
^
StudentRecordExample.java:18: cannot find symbol
symbol : class StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord crisRecord =new StudentRecord();
^
StudentRecordExample.java:18: cannot find symbol
symbol : class StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord crisRecord =new StudentRecord();
^
StudentRecordExample.java:21: cannot find symbol
symbol : variable StudentRecord
location: class studentpackage.StudentRecordExample
StudentRecord.increaseStudentCount();
^
StudentRecordExample.java:32: cannot find symbol
symbol : variable StudentRecord
location: class studentpackage.StudentRecordExample
System.out.println("Count="+StudentRecord.getStudentCount());
^
10 errors
The compile error occurs because StudentRecordExample class uses StudentRecord class and the javac compiler could not find the StudentRecord class in the default classpath. Since you did not specify the "-classpath
5. Specify the classpath for compilation as well. Now the compilation of both files should succeed.
* javac StudentRecord.java
* javac -classpath . StudentRecordExample.java
Exercise 10.4: Packaging at the command line
Please do this exercise at the command line instead of using NetBeans. This is to learn the concept of packaging without the help of NetBeans.
Introduction:
You already have some exposure to the concept of a package. A Java package is basically a collection of Java classes. One important thing you have to remember is that a Java package structure should be reflected in the directoryt structure in the file system. In this exercise, you will do a bit more comprehensive exercise involving classpath and packaging structure. Please feel free to do some more experimentation of your own.
* If you are new to Packaging concept, please read "Creating and Managing Packages" section of the Java Progamming Tutorial.
Steps to follow
1. Modify StudentRecord.java as following to add a package statement as shown in Code-10.4.a below. By adding package statement, you are basically saying the StudentRecord class now belongs to studentpackage package. The code fragement that needs to be added is highlighted with bold and blue-colored font.
package studentpackage;
public class StudentRecord {
...
}
Code-10.4.a: StudentRecord.java with package statement
2. Modify StudentRecordExample.java as shown in Code-10.4.b below to add a package statement. By adding package statement, you are basically saying the StudentRecordExample class now belongs to studentpackage package. The code fragement that needs to be added is highlighted with bold and blue-colored font.
package studentpackage;
public class StudentRecordExample{
...
}
Code-10.4.b: StudentRecordExample.java with package statement
3. Compile code.
* cd \myjavaprograms (if you are not in this directory already)
* del StudentRecord.class (just to start from a clean slate)
* del StudentRecordExample.class (just to start from a clean slate)
* javac StudentRecord.java StudentRecordExample.java
4. Run the code. You will experience an NoClassDefFoundError exception as shown below.
* java -classpath . StudentRecordExample
Think about why you are getting this exception for a moment. It is because the java runtime is trying to find StudentRecordExample.class under studentpackage directory since the StudentRecordExample.java now has a package studentpackage; statement, which indicates that the Java class file resides under studentpackage directory.
* C:\myjavaprograms>java -classpath . StudentRecordExample
Exception in thread "main" java.lang.NoClassDefFoundError: StudentRecordExample
(wrong name: studentpackage/StudentRecordExample)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
5. Create a new directory called strudentpackage and then move StudentRecord.java and StudentRecordExample.java under it.
* mkdir \myjavaprograms\studentpackage
* move \myjavaprograms\StudentRecordExample.java \myjavaprograms\studentpackage\StudentRecordExample.java
* move \myjavaprograms\StudentRecord.java \myjavaprograms\studentpackage\StudentRecord.java
6. Compile the code. You will experience compile errors as following. You get this compile error because you are trying to compile the two Java files that are not present in the current directory anymore.
* cd \myjavaprograms (if you are not in this directory already)
* del StudentRecord.class
* del StudentRecordExample.class
* C:\myjavaprograms>javac StudentRecord.java StudentRecordExample.java
error: cannot read: StudentRecord.java
1 error
7. Compile the code using a directory structure. The compilation should succeed. Note that the class files are now created under studentpackage directory not in the current directory
* javac studentpackage\StudentRecord.java studentpackage\StudentRecordExample.java
* C:\myjavaprograms>dir studentpackage
Volume in drive C is S3A1256D004
Volume Serial Number is 447E-6EBC
Directory of C:\myjavaprograms\studentpackage
07/06/2005 12:39 PM DIR .
07/06/2005 12:39 PM DIR ..
07/06/2005 12:40 PM 1,499 StudentRecord.class
07/06/2005 12:16 PM 1,425 StudentRecord.java
07/06/2005 12:40 PM 880 StudentRecordExample.class
07/06/2005 12:17 PM 690 StudentRecordExample.java
4 File(s) 4,494 bytes
2 Dir(s) 1,415,856,128 bytes free
8. Run the code as following. You will experience NoClassDefFoundError because Java runtime now is trying to find the class in the current directory instead of in the studentpackage directory.
* C:\myjavaprograms>java -classpath . StudentRecordExample
Exception in thread "main" java.lang.NoClassDefFoundError: StudentRecordExample
9. Run the code with propert package structure. It should work this time.
* C:\myjavaprograms>java -classpath . studentpackage.StudentRecordExample
Anna
Count=3
10. Now you thught you should be able to run the application under the studentpackage directory itself so you go into the directory and run the code. And the following is what you will experience. It is because it is still looking for studentpackage/StudentRecordExample.class in the currently directory and it could not find it.
* C:\myjavaprograms>cd studentpackage
C:\myjavaprograms\studentpackage>java -classpath . StudentRecordExample
Exception in thread "main" java.lang.NoClassDefFoundError: StudentRecordExample
(wrong name: studentpackage/StudentRecordExample)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
11. Now can specify the classpath using -classpath command line option as following. The reason you are experiencing the problem is because you do not provide the proper directory structure when invoking the application even though you gave the correct classpath.
* C:\myjavaprograms\studentpackage>java -classpath \myjavaprograms StudentRecordExample
Exception in thread "main" java.lang.NoClassDefFoundError: StudentRecordExample
12. Now use correct directory structure of the class.
* C:\myjavaprograms\studentpackage>java -classpath \myjavaprograms studentpackage.StudentRecordExample
Anna
Count=3
Homework:
1. Write a class called Food under foodpackage.fruitpackage pacakge
* Food.java should have the following package statement at the top
o package foodpackage.fruitpackage
* Add a couple of methods of your own in the Food.java.
2. Write a class called FoodMain under foodpackage.fruitpackage package
* FoodMain class creates an Food object
* FoodMain class then calls a method of Food object
3. Compile and run the code
Hint: The goal of this homework exercise is to let you experience s two-level package structure instead of just one. For example, the "foodpackage" is a parent package of the "fruitpackage" package. And each should have its own directory and they should reflect the parent and child relationship of the package structure. What this means is that you would have to create foodpackage directory first and then fruitpackage directory underneath it. Then you will create Food.java and FoodMain.java under fruitpackage directory.
Introduction:
You already have some exposure to the concept of a package. A Java package is basically a collection of Java classes. One important thing you have to remember is that a Java package structure should be reflected in the directoryt structure in the file system. In this exercise, you will do a bit more comprehensive exercise involving classpath and packaging structure. Please feel free to do some more experimentation of your own.
* If you are new to Packaging concept, please read "Creating and Managing Packages" section of the Java Progamming Tutorial.
Steps to follow
1. Modify StudentRecord.java as following to add a package statement as shown in Code-10.4.a below. By adding package statement, you are basically saying the StudentRecord class now belongs to studentpackage package. The code fragement that needs to be added is highlighted with bold and blue-colored font.
package studentpackage;
public class StudentRecord {
...
}
Code-10.4.a: StudentRecord.java with package statement
2. Modify StudentRecordExample.java as shown in Code-10.4.b below to add a package statement. By adding package statement, you are basically saying the StudentRecordExample class now belongs to studentpackage package. The code fragement that needs to be added is highlighted with bold and blue-colored font.
package studentpackage;
public class StudentRecordExample{
...
}
Code-10.4.b: StudentRecordExample.java with package statement
3. Compile code.
* cd \myjavaprograms (if you are not in this directory already)
* del StudentRecord.class (just to start from a clean slate)
* del StudentRecordExample.class (just to start from a clean slate)
* javac StudentRecord.java StudentRecordExample.java
4. Run the code. You will experience an NoClassDefFoundError exception as shown below.
* java -classpath . StudentRecordExample
Think about why you are getting this exception for a moment. It is because the java runtime is trying to find StudentRecordExample.class under studentpackage directory since the StudentRecordExample.java now has a package studentpackage; statement, which indicates that the Java class file resides under studentpackage directory.
* C:\myjavaprograms>java -classpath . StudentRecordExample
Exception in thread "main" java.lang.NoClassDefFoundError: StudentRecordExample
(wrong name: studentpackage/StudentRecordExample)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
5. Create a new directory called strudentpackage and then move StudentRecord.java and StudentRecordExample.java under it.
* mkdir \myjavaprograms\studentpackage
* move \myjavaprograms\StudentRecordExample.java \myjavaprograms\studentpackage\StudentRecordExample.java
* move \myjavaprograms\StudentRecord.java \myjavaprograms\studentpackage\StudentRecord.java
6. Compile the code. You will experience compile errors as following. You get this compile error because you are trying to compile the two Java files that are not present in the current directory anymore.
* cd \myjavaprograms (if you are not in this directory already)
* del StudentRecord.class
* del StudentRecordExample.class
* C:\myjavaprograms>javac StudentRecord.java StudentRecordExample.java
error: cannot read: StudentRecord.java
1 error
7. Compile the code using a directory structure. The compilation should succeed. Note that the class files are now created under studentpackage directory not in the current directory
* javac studentpackage\StudentRecord.java studentpackage\StudentRecordExample.java
* C:\myjavaprograms>dir studentpackage
Volume in drive C is S3A1256D004
Volume Serial Number is 447E-6EBC
Directory of C:\myjavaprograms\studentpackage
07/06/2005 12:39 PM DIR .
07/06/2005 12:39 PM DIR ..
07/06/2005 12:40 PM 1,499 StudentRecord.class
07/06/2005 12:16 PM 1,425 StudentRecord.java
07/06/2005 12:40 PM 880 StudentRecordExample.class
07/06/2005 12:17 PM 690 StudentRecordExample.java
4 File(s) 4,494 bytes
2 Dir(s) 1,415,856,128 bytes free
8. Run the code as following. You will experience NoClassDefFoundError because Java runtime now is trying to find the class in the current directory instead of in the studentpackage directory.
* C:\myjavaprograms>java -classpath . StudentRecordExample
Exception in thread "main" java.lang.NoClassDefFoundError: StudentRecordExample
9. Run the code with propert package structure. It should work this time.
* C:\myjavaprograms>java -classpath . studentpackage.StudentRecordExample
Anna
Count=3
10. Now you thught you should be able to run the application under the studentpackage directory itself so you go into the directory and run the code. And the following is what you will experience. It is because it is still looking for studentpackage/StudentRecordExample.class in the currently directory and it could not find it.
* C:\myjavaprograms>cd studentpackage
C:\myjavaprograms\studentpackage>java -classpath . StudentRecordExample
Exception in thread "main" java.lang.NoClassDefFoundError: StudentRecordExample
(wrong name: studentpackage/StudentRecordExample)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
11. Now can specify the classpath using -classpath command line option as following. The reason you are experiencing the problem is because you do not provide the proper directory structure when invoking the application even though you gave the correct classpath.
* C:\myjavaprograms\studentpackage>java -classpath \myjavaprograms StudentRecordExample
Exception in thread "main" java.lang.NoClassDefFoundError: StudentRecordExample
12. Now use correct directory structure of the class.
* C:\myjavaprograms\studentpackage>java -classpath \myjavaprograms studentpackage.StudentRecordExample
Anna
Count=3
Homework:
1. Write a class called Food under foodpackage.fruitpackage pacakge
* Food.java should have the following package statement at the top
o package foodpackage.fruitpackage
* Add a couple of methods of your own in the Food.java.
2. Write a class called FoodMain under foodpackage.fruitpackage package
* FoodMain class creates an Food object
* FoodMain class then calls a method of Food object
3. Compile and run the code
Hint: The goal of this homework exercise is to let you experience s two-level package structure instead of just one. For example, the "foodpackage" is a parent package of the "fruitpackage" package. And each should have its own directory and they should reflect the parent and child relationship of the package structure. What this means is that you would have to create foodpackage directory first and then fruitpackage directory underneath it. Then you will create Food.java and FoodMain.java under fruitpackage directory.
Subscribe to:
Posts (Atom)