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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:07:52+00:00 2026-06-01T08:07:52+00:00

I’ve created a Vector2D class that extends Point2D.Double . A Vector2D has two fields:

  • 0

I’ve created a Vector2D class that extends Point2D.Double.

A Vector2D has two fields: magnitude and direction. The extension of Point2D.Double allows the vector to store a starting location as well.

I like the ability to do this:

Vector2D myVector = new Vector2D(50, 50);  // instantiated without direction or magnitude
Point2D.Double myPoint = new Point2D.Double(myVector.getLocation());

However, I’d like to disallow this:

Point2D.Double myPoint = myVector;

And this:

Point2D.Double myPoint.setLocation(myVector);

Because both of these operations treat a myVector as if it is just a Point2D.Double.

I know that Java doesn’t allow overriding or overloading of operators, so the first undesired case seems especially difficult to eliminate. I also know that I can override .setLocation() with an empty method body (to prevent its use), but that’s not really a great solution.

Is there a way to disallow Vector2D methods or operators that exist in Point2D.Double?

  • 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-01T08:07:53+00:00Added an answer on June 1, 2026 at 8:07 am

    I’m failing to see the issue here. If you want Vector2D to be a subclass of Point2D.Double, then you are explicitly declaring that it IS a Point2D.Double. If the client wants to use it as a Point2D.Double that is allowed, and completely legitimate.

    It sounds like what you are trying to accomplish is subclassing as a code reuse system, rather than as a true is-a relationship. This is generally considered an anti-pattern.

    Either accept that clients can do this (even though you dislike it), or switch to a composition object instead.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters

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.