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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:54:07+00:00 2026-05-14T16:54:07+00:00

in A Programmers Guide to Java SCJP Certification I found an example which I

  • 0

in “A Programmers Guide to Java SCJP Certification” I found an example which I can’t follow.

This the given enum:

enum Scale3 {
    GOOD(Grade.C), BETTER(Grade.B), BEST(Grade.A);

    enum Grade {A, B, C}

    private Grade grade;

    Scale3(Grade grade) {
        this.grade = grade;
    }

    public Grade getGrade() { return grade; }
}

This is the given expression:

Scale3.GOOD.getGrade().compareTo(Scale3.Grade.A) > 0;

I don’t understand why this expression will be true?
The return value will be 2.

compareTo() will return a value > 0 if the given object is “less” than the object.

Scale3.Grade.A is the “biggest” element of Grades, its ordinal number is 0.

Scale3.GOOD is the “biggest” element of Scale3, its ordinal number is also 0.

The constructor of Scale3 is called with Scale3.Grade.C, which ordinal number is 2.

So the given expression is equal to the following code:

Scale3.Grade.C.compareTo(Scale3.Grade.A) > 0;

A is “bigger” than C, so shouldn’t be the result < 0?

  • 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-14T16:54:07+00:00Added an answer on May 14, 2026 at 4:54 pm

    Enums implement the Comparable interface, and the comparison is based on their ordinal number (their position in the enum declaration).

    The ordinal value of Scale3.Grade.A is 0, and the ordinal value of Scale3.Grade.C is 2. Therefore, C is “bigger” than A.

    See the implementation of Enum.compareTo(E o).

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

Sidebar

Related Questions

In the book 'A Programmer's guide to Java SCJP certification by Khalid Mughal -
I was reading A Programmer’s Guide to Java™ SCJP Certification by Khalid Mughal. In
I am going through Programming Ruby - a pragmatic programmers guide and have stumbled
i need to develop a .net library which exposes a java web service proxy
In the official Java guide Programming with assertions it is stated that (last paragraph
I am learning ruby from a book I got called The Pragmatic Programmers Guide
I am new to Android programming and was referring a Programmers' guide to know
This is a question of curiosity about accepted coding practices. I'm (primarily) a Java
Is thare any quickstart guide for programmers for writing DSP-accelerated appliations for TMS320C64x? I
Good morning, afternoon, evening or night (depending on your timezone). This is just a

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.