File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes problem with inheritance from multiple files ( in the same package) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem with inheritance from multiple files ( in the same package)" Watch "problem with inheritance from multiple files ( in the same package)" New topic
Author

problem with inheritance from multiple files ( in the same package)

sai panindra
Greenhorn

Joined: Jan 06, 2009
Posts: 5
// in file base.java
package p1;
import java.io.*;
import java.util.*;


public class base
{
int n=1;
public int n1=3;
public base()
{
System.out.println("fdfs"+n1);
}

public static void main(String args[])
{
base obj=new base();
}
}

// in file derived.java

package p1;
import java.io.*;
public class derived extends base
{
derived()
{
System.out.println("asfsdf"+n1);
}
public static void main(String args[])
{
derived obj1=new derived();
}
}


i put both the files in a folder named p1.
compiled the base.java successfully.
When i try compiling derived.java, it shows an error stating that it cannot find symbol "base".
Please tell me the reason for this..

Thanks
Aurelian Tutuianu
Ranch Hand

Joined: May 13, 2004
Posts: 86
Probably you compile independently each class.
If that is the case you should provide the paths to look for other classes used by the sources you compile.
Because you cmpaile second class alone, you should provide the path to base class.
You do that by:


Second options is: use an IDE, it can save your life time!


http://javasign.blogspot.com/
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37980
    
  22
Please use the code button so we can easily read the code.

Your problem is more to do with how you compile files inside packages. You haven't told us which directories your source files are in. A lot of these problems stem from not understanding the directory structure. There are several recent posts about compiling files with packages, which is by no means easy. Look at this thread and my post on 22nd January and the links I quote there. That should lead you to several old threads about similar problems, which I think will be helpful.
 
 
subject: problem with inheritance from multiple files ( in the same package)
 
Similar Threads
Protected Constructors
packages
One more doubt
package/classpath
What are the steps involved in complilation of the program?