• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem Related Inhertiance Compilation On Dos.  RSS feed

 
Pulkit Malhotra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I'm having two classes as following.

public class Father {

public static void main (String[] args)
{
System.out.println("Father Class");
}
void MyName()
{
System.out.println("I'm Father");
}

}

public class Son extends Father {

public static void main (String[] args)
{
System.out.println("Son Class");
}

void MyName()
{
System.out.println("I'm Son");
}
}


Both the classes in the same directory , when compling Father class and running it gives me proper output when i'm compling the Son class it throws the following error.

Son.java:1: cannot resolve symbol
symbol : class Father
location: class Son
public class Son extends Father {
^
1 error


I'm having following version of java and running it on Win xp SP2.

java version "1.4.2_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_11-b06)
Java HotSpot(TM) Client VM (build 1.4.2_11-b06, mixed mode)

I'm not able to find out the cause please help me.

Thanks.


Regards,
Pul_Mal.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try compiling with the classpath option of the current directory (indicated by a dot ".") as follows:

javac -cp . Son.java

If this works, it indicates that your system CLASSPATH variable needs to have the dot added to it. (Or better yet, remove the system CLASSPATH variable entirely, unless you know that you need it.)
 
Pulkit Malhotra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With javac -classpath . Son.java. It works.

Thanks for your quick reply.

Should i remove the classpath from enivormental variables ?.

Regards,
Pul_Mal
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pulkit Malhotra:
...Should i remove the classpath from enivormental variables? ...

What exactly is listed in the system CLASSPATH now?

It's possible that it might be used by something else, so let's see what's there first.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hate to take the topic in a different direction, but the whole inheritance thing isn't being used quite properly. Inheritance represents an is-a relationship, and your code indicates that a Father is-a Child. That seems kinda awkward.

Also, Roles that people play, like father, son, manager or secretary, should be expressed with an inteface, not inheritance.

Just a heads up. If the code you write helps you learn, then there's nothing wrong with it.

Cheers!

-Cameron McKenzie
 
Pulkit Malhotra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestion. I had just tried a sample example.
You told me right point to consider.

Thanks again.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Cameron W. McKenzie:
your code indicates that a Father is-a Child.


I agree this this is a misuse of inheritance, but Son extends Father -- i.e., Son is-a Father, not the other way around.


In any event, I think it's not real code anyway, just learning.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!