• 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

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic