Skip to Main Content
Java™ Puzzlers: Traps, Pitfalls, and Corner Cases
book

Java™ Puzzlers: Traps, Pitfalls, and Corner Cases

by Joshua Bloch, Neal Gafter
June 2005
Beginner to intermediate content levelBeginner to intermediate
312 pages
6h 24m
English
Addison-Wesley Professional
Content preview from Java™ Puzzlers: Traps, Pitfalls, and Corner Cases

6. Classy Puzzlers

This chapter contains puzzlers that concern the use of classes and their instances, methods, and fields.

Puzzle 46: The Case of the Confusing Constructor

This puzzle presents you with two Confusing constructors. The main method invokes a constructor, but which one? The program’s output depends on the answer. What does the program print, or is it even legal?

public class Confusing {    private Confusing(Object o) {        System.out.println("Object");    }        private Confusing(double[ ] dArray) {        System.out.println("double array");    }    public static void main(String[ ] args) {        new Confusing(null);    }}

Solution 46: Case of the Confusing Constructor

The parameter passed to the constructor is the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

A Common-Sense Guide to Data Structures and Algorithms, Second Edition, 2nd Edition

A Common-Sense Guide to Data Structures and Algorithms, Second Edition, 2nd Edition

Jay Wengrow
Algorithms, 4th Edition

Algorithms, 4th Edition

Robert Sedgewick, Kevin Wayne

Publisher Resources

ISBN: 032133678XPurchase book