• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Sybex 816 Java OCP 11 Programmer II Study Guide

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java OCP 11 Programmer II Study Guide

145 page

2:  public class UseTreeSet {
3:     static class Rabbit{ int id; }
4:     public static void main(String[] args) {
5:        Set<Duck> ducks = new TreeSet<>();
6:        ducks.add(new Duck("Puddles"));
7:
8:        Set<Rabbit> rabbits = new TreeSet<>();
9:        rabbits.add(new Rabbit());  // ClassCastException
10: } }
Line 6 is fine. Duck does implement Comparable. TreeSet is able to sort it into the proper position in the set. Line 9 is a problem. When TreeSet tries to sort it, Java discovers the fact that Rabbit does not implement Comparable. Java throws an exception that looks like this:

Exception in thread "main" java.lang.ClassCastException:
  class Duck cannot be cast to class java.lang.Comparable

class Duck cannot be cast to class java.lang.Comparable -----
 
Marshal
Posts: 80485
455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
I presume that is the book by Boyarsky and Selikoff? Please look here, where I can't find what you showed. Pleas wait for Jeanne to see this thread; it would appear you have found a new erratum.
 
Vladimir Prud
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, yes, this is a book by Scott Selikoff and Jeanne Boyarsky,
but the title of OCP Oracle Certified Professional Java SE 11 Programmer II Study Guide: Exam 1Z0-816 and Exam 1Z0-817
I bought it at https://www.wiley.com



I am reading a book on vitalsource, perhaps the page numbers are not quite correct there. an example is located in chapter 3, just above the topic "Working with Generics"
 
author & internet detective
Posts: 42109
934
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's on page 147 in the printed book, so pretty close.

Definitely should be Rabbit, not Duck. I've added it to the errata. Quack!
 
Vladimir Prud
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,I found another typo, 436 page,8 chapter

Manipulating Input Streams
All input stream classes include the following methods to manipulate the order in which data is read from a stream:

// InputStream and Reader
public boolean markSupported()
public void void mark(int readLimit)

public void reset() throws IOException

public long skip(long n) throws IOException

 
Campbell Ritchie
Marshal
Posts: 80485
455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I presume you have checked the errata because that does look like an error. You can't usually use the same keyword twice.
 
Jeanne Boyarsky
author & internet detective
Posts: 42109
934
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Confirmed and added to the errata. Thanks for noticing!
reply
    Bookmark Topic Watch Topic
  • New Topic