• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sai panindra
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
// 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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Campbell Ritchie
Sheriff
Posts: 48386
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic