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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:02:09+00:00 2026-05-26T16:02:09+00:00

public abstract class Main implements Comparable { public static void main(String[] args) { Integer[]

  • 0
public abstract class Main implements Comparable {

    public static void main(String[] args) {
        Integer[] intArray = {1,2,3,4,5,6,7,8,9,10};
        String[] stringArray = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};
        java.util.Date[] dateArray = {};

        for (int j = 0; j < 10 ; j++)
            dateArray[j] = new java.util.Date();

      /* Code to call max method and display the largest value of these */



    }

    public static Object max (Comparable[] a){
        Object tempObj = new Object();

        for (int i = 0; i < a.length - 1; i++){
            if ((a[i]).compareTo(a[i+1]) > 0 )
                tempObj = a[i];
            else 
                tempObj = a[i+1];
        }

        return tempObj;
    }

    public int compareTo(Object o) {

            if (/*this*/ > o)
                return 1;
            else if (/*this*/ < o)
                return -1;
            else
                return 0;
        }
}

While it may be easier to write it in a generic max(a, b) format, one of the requirements is for it to be written this way. I can’t find a way to reference the value of the object that
is actually calling the compareTo method.

  • 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-26T16:02:10+00:00Added an answer on May 26, 2026 at 4:02 pm

    Concerns:

    • Why does Main implement Comparable? — it shouldn’t.
    • Why is Main abstract? — it shouldn’t be.
    • Why do you have your own compareTo method in your code? — you shouldn’t. It’s never called anyway (nor should it be).

    Instead just use the compareTo method that you know your Comparable objects have. You know that each item in the a array, no matter what type of item it is, implements Comparable, and so you can call this method directly on the item:

    For example,

    a[i].compareTo(a[i+1])
    

    You know of course that the simplest solution is to just call java.util.Arrays.sort(a) on the array a and just take the 0th item.

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

Sidebar

Related Questions

package geometricobject; public abstract class GeometricObject implements Comparable { private String color = white;
public abstract class MyAbs implements Comparable<MyAbs> This would work but then I would be
I have the following class: public abstract class AbstractParent { static String method() {
public abstract class Master { public void printForAllMethodsInSubClass() { System.out.println (Printing before subclass method
I have an abstract entity: public abstract class Entity extends JPanel implements FocusListener And
Given the following code: using System.Collections.Generic; static class Program { static void Main() {
I want something like this: public abstract class ListenerEx<LISTENER, PARENT> implements LISTENER { PARENT
I have three java types as defined below: Main.java: import java.util.Arrays; import java.util.List; public
Consider the following simple code import java.util.*; public class MainTest<T extends Object1<?,?>> { List<T>
public abstract class Request { public class Parameters { //Threre are no members here

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.