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

  • SEARCH
  • Home
  • 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 9232719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:22:50+00:00 2026-06-18T06:22:50+00:00

In the (default package) I have a class called Bird that has a method

  • 0

In the (default package) I have a class called “Bird” that has a method called “dialog”.

I can create a class called Class1 within the same package, like this:

public class Class1
{
    public static void main(String[] args) 
    {
        Bird b = new Bird("Alexander",true,5);
        b.dialog("tweet!");
    }
}

This actually works and I actually get to see tweet! in the console.

My question is: what do I need to add in the code if Class1 is located in the package Fundamental (whereas the class Bird is located in the “default package”)?
I get an error: “Bird type not recognised” in this case. I should probably indicate the package somehow.

Side questions: 1. What is a classpath and how do you change it? I have seen this term vaguely used in the context of several package-related discussions, but none with clear examples as I just gave.
2. I have seen many times packages called xxx.bla.zzz – is this a standard? I only usually use a common name (not three separated by .)
I understand a package is Java’s replacement for namespaces in other languages. If there are several solutions solutions worth mentioning, I’d appreciate. Thank you!

  • 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-06-18T06:22:52+00:00Added an answer on June 18, 2026 at 6:22 am

    You should never use the default package, it is not a good practice and you can’t import classes from the default package. Always declare your package structure.

    In the class Bird in the first line add:

    package animals;
    

    In the first line of your Class1.java write your package name

    package foo;
    
    import animals.Bird;
    

    Note that for this to work the class Bird and the class Class1 should be respectively in the folder “animals” and the folder “foo”

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

Sidebar

Related Questions

My Moo based class has both lazy & non-lazy attributes which have both default
in struts 2 execute method is not called by default. I have HelloWorld.java as
I have multiple XML configs. struts.xml <struts> <include file=struts-user.xml /> <package name=baseInterceptors extends=struts-default> <interceptor
I have an ORM class called Person, which wraps around a person table: After
Possible Duplicate: Selecting class by Maven build profile I have two packages called com.app.util
I have a problem with the default package. Basically my project structure consists of
This seems to have most started since I upgrade my DBIx::Class and I can't
I have a model class with a persisted DateTime field that is only interacted
I have an app that replies to any received SMS with a default message.
My default package name is com.xont.controller (R file contain that package.Eclipse generated one) .

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.