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 7539615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:25:51+00:00 2026-05-30T07:25:51+00:00

I have a dilemma with this, I am designing a project and basically it

  • 0

I have a dilemma with this, I am designing a project and basically it will have a baseclass -> entityclass relationship where the entity class inherits from the baseclass. Now the base class is abstract and would have something like:

abstract class MyAbstractClass{

//All this methods need to be implemented
abstract int getHouseId(int id);
abstract string getHouseName(String s);

}

Then I would like to do something like:

 public class MyChildClass extends MyAbstractClass{

    private int _hId = 0;
    private String _hName = "";

    public int getHouseId(int id)
    {
       if(id > _hId)
       {
          return _hId;
       }
       return id;
    }
    public String getHouseName(String s)
    {
        if(s.Equals(_hName))
        {
           return _hName; 
        }
        return s;
     }

      //AND YOU HAVE YOUR SETTERS SOMEWHERE HERE
   }

Now please excuse if syntax error, I just made it on the fly, my question is is it better to declare the variables in the abstract class and set and get stuff from there, or create the variables in the child class?. I am confused by it, also if using it in the abstract class, how should they be declared in the abstract class, can I make them private there and add properties to get the values?, or it is better to do it in the child class?. Basically I want to enforce a set of programmers to always use the abstract class as the functions that they HAVE to implement.. just a bit confused about the concept. I tried to google it but did not see many articles about variables and properties in an abstract class, maybe it should be used in the child class. Thank you for your help making me understand this.

  • 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-30T07:25:53+00:00Added an answer on May 30, 2026 at 7:25 am

    is it better to declare the variables in the abstract class and set and get stuff from there, or create the variables in the child class?.

    The idea is to minimize the duplication. If you are duplicating the the logic and variables in each subclass, then better have it in super-class.

    …if using it in the abstract class, how should they be declared in the abstract class, can I make them private there and add properties to get the values?,

    The general practice is to make the variable private in abstract class. And modify/access them using public/protected getter/setter.

    Basically I want to enforce a set of programmers to always use the abstract class as the functions that they HAVE to implement..

    So, here you go. Have the attribute and getter/setter in abstract class. And make only those methods abstract that you want your devs to implement with their own logic.

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

Sidebar

Related Questions

If you could help me with this dilemma I have. Now, I know C
Basically my dilemma is this. I have a list of x servers that host
I have this dilemma about designing/programming border or gap widths in an application of
We have a dilemma; developing desktop application using Matisse or Jigloo.. Matisse has this
Okay, my dilemma is this. I have an admin page that I use to
I have a dilemma with this one. With the following code I am able
I have an interesting dilemma. If I define my class as: class Browser {
I have a dilemma that goes like this. I have a string that represents
I have this dilemma. I'm developing a web services. It has to return a
I have this dilemma with JavaScript. I need to convert a list of dates

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.