Note that there are some explanatory texts on larger screens.

plurals
  1. POMy toString() method isn't overriding the Calendar toString() method
    primarykey
    data
    text
    <p>Here is my code, pretty simple really. Its not homework, I'm teaching myself java through an education book:</p> <hr> <pre><code>import java.util.*; /** @author Chris */ public class Exercise9_9 extends GregorianCalendar { public static void main(String[] args) { String[] stringList = {"s", "c", "b", "f", "e", "q", "g", "w", "i", "o"}; Integer[] integerList = {5, 7, 8, 9, 6, 5, 4, 1, 2, 3}; Calendar[] calendarList = new Calendar[10]; for (int a = 0; a &lt; calendarList.length; a++) { calendarList[a] = new GregorianCalendar(); calendarList[a].set(Calendar.YEAR, ((int)Math.random()* 1000)); } System.out.println("Largest String: " + max(stringList)); System.out.println("Largest int: " + max(integerList)); **System.out.println("Largeset date: " + (max(calendarList)).toString());** } public static Object max(Object[] a) { Arrays.sort(a); return a[a.length-1]; } **@Override public String toString()** { return "Test"; } } </code></pre> <hr> <p>The question is to produce three arrays: int, String and Calendar type. Then pick out the biggest out of each category (and display the answers). </p> <p>This class extends the <code>GregorianCalendar</code> class which means I have access to the Calendars <code>toString()</code> which I'm trying to override. However it doesn't work. Its like the <code>toString()</code> method isn't overriding because I'm getting the default <code>toString()</code> output. However, I'm using Netbeans and it acknowledges the override and even takes me to to <code>Calendar.toString()</code> when I click the override link. So I'm stuck, any help would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload