• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

abstract superclass & concrete subclass

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question is from book scp for java6 by Kathy & Bert
excercise for reader -
Create an abstract superclass named Fruit and a concrete subclass named Apple. The superclass should belong to a package called food and the subclass can belong to the default package . Make the superclass public and give the subclass default access.

1. Create the superclass as follows:
package food;
public abstract class Fruit{ /* any code you want */}
2. Create the subclass in a separate file as follows:
import food.Fruit;
class Apple extends Fruit{ /* any code you want */}
3. Create a directory called food off the directory in your class path setting.

JDK path : C:\Program Files\Java
I have not set CLASSPATH in the environment variable (default it looks into current directory).
The files where my java programs (programs which i write for practise) are stored in C:\JavaFiles folder so my question is -
Create a directory called food off the directory in your class path setting (question in the book), where exactly do i have to place the food folder which has the fruit class in it ?


So what i Did was placed
The fruit.java file in c:\javaFiles\Food\Fruit.java
The apple.java file in c:\javaFiles\Apple.java

compiled it
c:\javaFiles> javac Fruit.java
c:\javaFiles> javac Apple.java

and there was no error.. after i run the program..

But i am a bit embarrassed to ask what does the point 3 in the question askin me to do.. (set ClassPath ? )
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the delay. This was in a forum other than SCJP. I've moved it for you.

I don't follow the question. Which chapter in the book was it in? Knowing if it was in the OO chapter or final chapter or somewhere else would give the context which would help us point you int he right direction.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Which chapter in the book was it in?


It's exercise 1-1 on page 18 in the 1st chapter "Declarations and Access Control".

(I also added the topic to the OCAJP7 forum, because the OP could be using K&B6 to prepare for that certification).
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't appear anything because you just compile the java file. A .class file has been created for you and now remains to run the command [java filename]
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Princy Sinish wrote:But i am a bit embarrassed to ask what does the point 3 in the question askin me to do.. (set ClassPath ? )


No reason to be embarrassed, you did the right thing: you created the directory food inside the directory you are using to run java/javac from (c:\javaFiles). So the default is the current directory and that's why both compilations finished successfully (without any error). If you would have compiled from another location you would have had compiler errors and needed to add c:\javaFiles to your classpath using the -cp option.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


3. Create a directory called food off the directory in your class path setting.



I believe they want developer to test the capability when food is created outside the CLASSPATH.

And i do not think so that you did the right thing because you created in the same folder where javac will see
it in the default library path i.e. from where it executed.

I hope it clears your doubt. Let me know if you have any doubts.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitin Mah wrote:I believe they want developer to test the capability when food is created outside the CLASSPATH.


Based on other threads on this forum (here, here and here) I think you are correct

So you should create the food directory in another directory than the one you use to run javac from. You will be required to use -classpath (or -cp) option to successfully compile the Fruit class.

So based on the OP's 1st post:
  • Create 2 directories on your hard drive: javaFiles and otherJavaFiles
  • In directory otherJavaFiles create subdirectory food and the Fruit class
  • In directory javaFiles create the Apple class
  • Using the command line change the current directory to directory javaFiles and try to successfully compile both Java classes


  • Good luck!

     
    reply
      Bookmark Topic Watch Topic
    • New Topic