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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:43:26+00:00 2026-05-28T04:43:26+00:00

I am pretty new to Java, so I may be using incorrect terminology. I

  • 0

I am pretty new to Java, so I may be using incorrect terminology. I am trying to gracefully extend a class to a new class which holds multiple instances of the superclass. For example, say I have a class

class Rose{
   String smell;
   Rose(String smell){this.smell=smell;}
   void sniff(){ println("smells "+smell);}
}

And I want to define a class like…

class Bouquet extends Rose{
   ArrayList<Rose> roses;
   ...
}

holding multiple roses. My actual code has something like 20 methods, and for most of them the extended method would be

void sniff(){
   for( Rose one: roses) one.sniff();
}

Is there a way to construct bouquet in such a way that I don’t need to explicitly define these silly loops? I’m not tied to ArrayList, I could even make a new super class if that’s the way to go about it. However, it is important that I can send a bouquet instead of a rose argument to externally written methods.

EDIT:
Haha, I think my flower metaphor was a big fail. 🙂 But your input is good; you guys have clarified my thinking a bit.

In my real problem, there are a set of operations that define how to add instances of the base class together into a new instance of the base class. Perhaps a better metaphor would be twisting a number of small fabric strands together into one rope. External methods should treat a rope and a strand exactly the same.

It does seem like extends is wrong, any other suggestions?

  • 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-28T04:43:26+00:00Added an answer on May 28, 2026 at 4:43 am

    You dont really need to extend bouquet from roses. You extend only when there is an IS A relationship, like you have Flower class and Rose is a Flower. But bouquet is not a rose. Ideally you should have a bouquet class which HAS many roses. If there is a 1:N relationship, then you will have to loop through to get individual items.

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

Sidebar

Related Questions

I'm pretty new to Java ME and i'm trying to use Microlog to handle
I am new to Java world but I am pretty good at using Flex,
I'm pretty new to java, and using netbeans for design a UI. What I
I'm pretty new to Java, let's say I have a String containing multiple things
I'm pretty new to Java and I'm finishing my first project using it. Basically
Im pretty new to Java Web Services, but I cant find a good explanation
I am pretty new to the whole Java and OSGi world and I have
I am completely new to android, and pretty much a Java newb. I have
I'm pretty new to Java, and I need to build up programming environments for
I'm pretty new to Java and SWT, hoping to have one image dissolve into

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.