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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:16:41+00:00 2026-06-14T09:16:41+00:00

I am currently preparing for Java SE 7 Programmer exam and I tried to

  • 0

I am currently preparing for Java SE 7 Programmer exam and I tried to solve the sample questions on the Oracle site. I got stuck at this one:

import java.util.*;
    public class Primes2 {
        public static void main(String[] args) {
            Integer[] primes = {2, 7, 5, 3};
            MySort ms = new MySort();
            Arrays.sort(primes, ms);
            for(Integer p2: primes)
                System.out.print(p2 + " ");
        }
     static class MySort implements Comparator {
         public int compare(Integer x, Integer y) {
             return y.compareTo(x);
         }
     }
}

What is the result?

A) 2 3 5 7

B) 2 7 5 3

C) 7 5 3 2

D) Compilation fails.

E) An exception is thrown at run time.

The question can be found here: http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=303&p_certName=SQ1Z0_804

The correct answer indicated on the site is C. I tested the code and found it did not compile, because Comparator is parameterized and in the given code the type was not indicated, therefore the compiler expected Object parameters for compare method. When I changed Comparator with Comparator<Integer>, the error was solved and it worked as expected.

My question is whether that declaration in the original code respects the standards of Java 7 and should compile.

  • 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-14T09:16:42+00:00Added an answer on June 14, 2026 at 9:16 am

    Effectively, that does not compile.

    In order to be valid, either Comparator must be typed as Comparator<Integer> or compare() methods arguments must be of Object Type.

    Thus, this exam question is invalid.

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

Sidebar

Related Questions

I am currently preparing myself for the exam in Networking and I got some
I'm currently preparing for an exam. One of the question I found in an
I'm preparing for an exam and one of the questions on a previous exam
I'm currently preparing a major Program-Update and ran into following problem: I've got a
I'm preparing to Microsoft Certificate exam (70-515), reading Microsoft book for this exam, practicing
In my project I'm currently preparing a step-by-step move from legacy code to new,
Currently I'm starting a new Activity and calling finish on a current one. Is
I am preparing to build a pre-existing Java project in NetBeans. I am reviewing
I'm currently preparing for an interview, and it reminded me of a question I
I'm occurring some trouble writing a basic webserver in JAVA. It's currently working fine

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.