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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:02:52+00:00 2026-05-14T01:02:52+00:00

Given that Date has a method called after(Date) and Timestamp has a method the

  • 0

Given that Date has a method called “after(Date)” and Timestamp has a method the overrides it called “after(Timestamp)”, why is the after method in Date called in the following code?

The question as to the unexpected results was asked here.

    java.sql.Timestamp one = new java.sql.Timestamp(1266873627200L);
    java.sql.Timestamp two = new java.sql.Timestamp(1266873627000L);

    java.util.Date oneDate = (java.util.Date) one;
    java.util.Date twoDate = (java.util.Date) two;


    System.out.println("one: " + oneDate.getTime());
    System.out.println("two: " + twoDate.getTime());

    if (oneDate.after(twoDate)) {
        System.out.println(oneDate.getTime() + " after " + twoDate.getTime());
    } else {
        System.out.println(oneDate.getTime() + " not after " + twoDate.getTime());
    }

results

one: 1266873627200
two: 1266873627000
1266873627200 not after 1266873627000
  • 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-14T01:02:52+00:00Added an answer on May 14, 2026 at 1:02 am

    Overloads are considered at compile-time; overrides are considered at execution time.

    Timestamp overloads after, it doesn’t override an existing method – so your oneDate.after(twoDate) is only considering the methods in java.util.Date; furthermore even if you use one.after(twoDate) it would still only use after(Date) because the compile-time type of twoDate is Date rather than Timestamp.

    If you call one.after(two) then that will use Timestamp.after(Timestamp).

    Date.after(Date) only considers the milliseconds – but Timestamp only passes an integral number of seconds to the constructor of Date, so oneDate and twoDate have an equal millisecond value in Date, even though you passed different values to the constructors.

    It’s worth noting this bit in the docs for Timestamp though:

    Due to the differences between the
    Timestamp class and the java.util.Date
    class mentioned above, it is
    recommended that code not view
    Timestamp values generically as an
    instance of java.util.Date. The
    inheritance relationship between
    Timestamp and java.util.Date really
    denotes implementation inheritance,
    and not type inheritance.

    Sounds like a pretty poor use of inheritance to me, to be honest – but then Java’s got plenty of those 🙁

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

Sidebar

Ask A Question

Stats

  • Questions 498k
  • Answers 498k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer vlc might work for ya May 16, 2026 at 12:13 pm
  • Editorial Team
    Editorial Team added an answer Null pointer is a special reserved value of a pointer.… May 16, 2026 at 12:13 pm
  • Editorial Team
    Editorial Team added an answer Try changing: addr.sin_port = port; To: addr.sin_port = htons(port); (The… May 16, 2026 at 12:13 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

The method I want to test has a local variable that references an object
I have a linq Entity called Enquiry, which has a property: string DateSubmitted. I'm
Given a tabbed delimited text file with two columns name and date: Sam 20100101
I have a control and it provides a selection mechanism. However, the items that
I have found this popular PHP/MySQL Script called Zip Location by SaniSoft and it
In a previous question , I was looking for an alternative to modifying how
PHP seems to use a rather annoying method for setting the evnironment timezone, using
I use a VB6/COM+ application which outputs date/time values based on the short date
I'm working with an XSL stylesheet, and I'm trying to use the method shown
I am trying to search for any string that contains ; in a column

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.