Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3879144
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:41:34+00:00 2026-05-19T22:41:34+00:00

When I create the base and derived class in the same directory without specifying

  • 0

When I create the base and derived class in the same directory without specifying any package they compile fine, but adding them to a package leads to an error in derived class saying that it is not able find he symbol of base class. This error is frustrating since I have been working in c before , why all these shenanigans in Java?.

package Testpackage; // If I comment this then derived class compiles fine

public class Test_class{

    int x,y;


    public static Integer angle;


    public Test_class(int a,int b)
{
    x = a;
        y = b;
}


    public Integer product()
{
    return x*y;
}
}

*************Derived class ****************
package Testpackage;  // If I comment this then it compiles fine

public class Derived_class extends Test_class{

       Integer vol;
      Test_class I = new Test_class(1,2); 
        public Derived_class(){
          super(9,10);
      vol = 0;
   }

       public Integer volume()
   {
         vol = this.product();

         return vol;
   }

}


********* output *************
assa@dasman-laptop:~/Testpackage$ javac Derived_class.java 
Derived_class.java:4: cannot find symbol
symbol: class Test_class
public class Derived_class extends Test_class{
                                   ^
Derived_class.java:7: cannot find symbol
symbol  : class Test_class
location: class Testpackage.Derived_class
          Test_class I = new Test_class(1,2); 
          ^
Derived_class.java:7: cannot find symbol
symbol  : class Test_class
location: class Testpackage.Derived_class
          Test_class I = new Test_class(1,2); 
                             ^
Derived_class.java:15: cannot find symbol
symbol  : method product()
location: class Testpackage.Derived_class
             vol = this.product();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:41:34+00:00Added an answer on May 19, 2026 at 10:41 pm

    When using packages, you should call your compiler from the directory at the root of the package hierarchy (in your case ~).

    So, go one directory up, and call javac this way:

    javac TestPackage/Derived_class.java
    

    Then the compiling should work. For executing, you then would use:

     java TestPackage.Derived_class
    

    (but your class does not have any main method yet.)


    Edit: Why is this necessary? When javac searches classes referenced from your classes, it searches them according to their package. Your Derived_class referenced the class TestPackage.TestClass, and this would be searched in TestPackage/TestClass.java (or .class) (relative to the classpath, which here consists of your working directory). No such directory exists, when you are already inside of the TestPackage directory.

    Another way to call it here would be to use

    javac -cp .. Derived_class.java
    

    since then javac would search the related classes from the parent directory. You should then also set the ‘-d’ parameter to put generated class files in the right structure. Call javac -help for a summary of the options, or look in your JDK documentation for a more detailed description of all the options.

    When you compile only a single file, it does not really matter, since the file to compile is given on the command line, and javac does not need to search more files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a Quicksort base class using VB.NET, taking it an array
In a C# program, I have an abstract base class with a static Create
I created instance of base class in derived class and tried to access protected
I want to create a class that could hold any of a number of
This link suggests to create an abstract base class that can read the job
I want to create templates for base new reports on to have common designs.
I'm using the following set of values to create a 9 character long base
I create a new Button object but did not specify the command option upon
I have a base class: class CBase { public: virtual void SomeChecks() {} CBase()
Possible Duplicates: Interface vs Base class Interface or abstract class? Hi All, I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.