javaoopinheritancefile-organization

Accessing BaseClass outside package java?


I have a series of classes in my java program as follows:

src
|
|- BaseCost
|- com.jdoe.nationalcosts
    |- EntryTicketCost
    |- FlightCost
|- com.jdoe.internationalcosts
    |- HotelCost

I'm trying to use BaseCost as and abrstract class that extends EntryTicketCost,FlightCost and HotelCost. However, my IDE says that it cannot resolve EntryTicketCost extends BaseCost. Am I organizing the files in the right way? If not, how am I supposed to order them for the inheritance to work?

If it helps, this is the shortened code for BaseCost

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.Arrays;
import java.util.List;

public abstract class BaseCost {
    private String id;
    private String name;
    private String description;
    private String costType;
    private int holder;

    public String getId() {...}

    public void setId(String id) {...}

    public String getName() {...}

    public void setName(String name) {...}

    public String getDescription() {...}

    public void setDescription(String description) {...}    
    public String getCostType() {...}

    public void setCostType(String costType) {...}

    public int getHolder() {...}

    public void setHolder(int holder) {...}

    public CalcValue getCalculated(int guides, int passengers){...}

    public void removeFromString(String string){...}

Solution

  • BaseCost is not in any package (basically in default package) hence you can not import it. Solution: Keep BaseCost in some package and import in EntryTicketCost as well as other classes where ever you are extending.

    Hope this help.