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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:49:18+00:00 2026-06-03T02:49:18+00:00

I am new to Java and am struggling with associations. I have a class

  • 0

I am new to Java and am struggling with associations. I have a class

public class A{
  private string name;

  public string get_name() {
    return name;
  }

  public void set_name(string name) {
    name = name;
  }
}

I have an association with another class B as association A -> B. It is one to one association. Now what I would like to do is to create another class C which is of type class A. So in other words, C is the same class as A but with different name. But there is 1 to many association between A and C. I would appreciate any help!

  • 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-03T02:49:20+00:00Added an answer on June 3, 2026 at 2:49 am

    If C is A with a different name why not just initialize an instance of A and name it C?

    A c = new A();
    c.set_name("Bob");
    

    Alternatively, if Cis going to change over time but be reliant on A make C extend A

    public class C extends A{
    
    }
    

    However, I would be wary of using the above as its generally a bad idea to make a superclass concrete (What if A changes down the line and you don’t want C to inherit those changes?). So, make A an interface/abstract class and make both C and Aconcrete implement it.

    Something like the following would be good…

    abstract class A{
      protected String name; //Protected so that subclasses can call it
    
      public String get_name() {
         return name;
      }
    
      public void set_name(String name) {
        this.name = name;
      }
    
    }
    
    class C extends A{
    
    
    }
    
    class Aconcrete extends A{
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Java Swing and I have been struggling to start the GridBagLayout
I'm new to Java EE and have been struggling with some basic middleware concepts
SimpleDateFormat formatter = new SimpleDateFormat(ddMMyyyy_HHmmSS); String strCurrDate = formatter.format(new java.util.Date()); String strfileNm = Cust_Advice_
SimpleDateFormat formatter = new SimpleDateFormat(ddMMyyyy_HHmmSS); String strCurrDate = formatter.format(new java.util.Date()); String strfileNm = Customer_
I have the following code adding an ActionListener to a JTextField: chatInput.addMouseListener(new java.awt.event.MouseAdapter() {
Completely new to java and I have been playing around with regex in a
I am new to java swing. I have pasted my code below for your
I am new to Spring programming and currently struggling with Spring 3.1's Java Based
I'm a new member. I have been struggling with sqlitejdbc, I thought. I made
import java.awt.Color; import java.awt.Graphics; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class MyDrawPanel extends

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.