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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:19:46+00:00 2026-05-28T01:19:46+00:00

I have several different type of Users (different classes) in my app User1 User2

  • 0

I have several different type of Users (different classes) in my app

User1

User2

etc…

I want to have an abstract class “User” that joins the same methods for all type of Users
ex: getId(), getAge()....

I don’t really know how that works but what i want to do is something like :

User.setType(2); //a kind a constructor
User.getId()... //etc .. the getId() method of the Users2 class

Without having to instantiate the abstract class User

How can I do that ?
The problem I have is that an abstract class can’t have static methods … and User must be static or a Singleton I don’t know what is the best.

could anyone give me some tips ?

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-05-28T01:19:47+00:00Added an answer on May 28, 2026 at 1:19 am
    public abstract class User {
        private int age;
        private int id;
    
        public int getAge() { return age; }
        public int getId() { return id; }
    }
    
    
    public class User1 extends User { }
    public class User2 extends User { }
    
    User user1 = new User1();
    user1.getId();
    User user2 = new User2();
    user2.getId();
    

    Without having to instantiate the abstract class User

    Abstract classes cannot be instantiated.

    User must be static or a Singleton I don’t know what is the best.

    Even though abstract classes can have static methods, that does not quite make sense (specially when you want an abstract User and multiple specific types of Users).

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

Sidebar

Related Questions

I have several different content type nodes (videos, image galleries, stories...) that I would
I have several web pages on several different sites that I want to mirror
Writing a PHP app and have several classes that only have static methods (no
I have several different c# worker applications that run various continuous tasks: sending emails
We have several different optimization algorithms that produce a different result for each run.
I have several different lists I want to call. They all have the same
I have several files that are in several different languages. I thought they were
I have used several different scripts that people have suggested for trying to parse
i have a little problem implementing some serialization/deserialization logic. I have several classes that
I have several keyboards and they type in different TMemos. In english, everything works

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.