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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:03:02+00:00 2026-06-03T01:03:02+00:00

I am developing application.. class Wheel { private int size; Wheel(int s) { size

  • 0

I am developing application..

    class Wheel {
    private int size;

    Wheel(int s) {
        size = s;
    }

    void spin() {
        System.out.print(size + " inch wheel spinning, ");
    }

}

public class Bicycle {
    public static void main(String[] args) {
        Wheel[] wa = { new Wheel(15), new Wheel(17) };
        for (Wheel w : wa)
            w.spin();
    }
}

But Please advise that how could we express Wheel[] wa = { new Wheel(15), new Wheel(17) }; in more simpler terms.

  • 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-03T01:03:03+00:00Added an answer on June 3, 2026 at 1:03 am

    If you want a shorter expression for creating an array of wheels, what you have is a simple as it can get without additional methods.

    You could create a factory method like so:

    class Wheel {
    
        public static Wheel[] newWheels( int[] sizes ){
            Wheel[] result = new Wheel[sizes.length];
            for( int i=0; i < sizes.length; i++ )
               result[i] = new Wheel( sizes[i] );
            return result;
        }
    
        // ... other stuff ...
    }
    

    Which would make your wheel creation statement:

    Wheel[] wa = Wheel.newWheels( new int[]{ 15, 17 } );
    

    Which isn’t much simpler when you only have two wheels of predetermined size, but if you have more of them, or if the sizes aren’t predetermined, this might be more readable.

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

Sidebar

Related Questions

I am developing an asp.net mvc application, which has these enity classes: public class
I'm developing an application which will have these classes: class Shortcut { public string
I’m developing MVC application and I have following classes in my model: public class
I am using C# and developing a winform application. I have a project class
I'm currently developing an application in which I'm using a plugin system. For providing
I am developing a application which requires to invoke a class function which is
I am developing an application in mootools. I have used Reqeust class to implement
I am developing an application to collect questions (class name Question ) and answers.
I am developing an application for Windows. I have written a class for drawing
I am struts2 for developing my application. Sample code of action class would be

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.