The Artima Developer Community
Sponsored Link

Java Buzz Forum
What Does It Print

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Weiqi Gao

Posts: 1808
Nickname: weiqigao
Registered: Jun, 2003

Weiqi Gao is a Java programmer.
What Does It Print Posted: May 12, 2004 1:18 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Weiqi Gao.
Original Post: What Does It Print
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Latest Java Buzz Posts
Latest Java Buzz Posts by Weiqi Gao
Latest Posts From Weiqi Gao's Weblog

Advertisement

(This was first posted 902 days ago. Zhicheng thought it's worth a repost.)

Question: What is printed when you run java Main?

// Main.java
class A {
    // A is a singleton.  The getInstance() method is even synchronized.
    private static A instance;
    public synchronized static A getInstance() {
        return (instance == null) ? (instance = new A()) : instance;
    }

    // A uses B
    private B b;
    private A() {
        b = new B();
    }
}

class B {
    // B caches the only instance of A
    public static A a = A.getInstance();
}

class Main {
    public static void main(String[] args) {
        System.out.println(A.getInstance() == B.a);
    }
}

Read: What Does It Print

Topic: Javablogs is timing out on my feed: anyone having a problem? Previous Topic   Next Topic Topic: Steve Vinoski on WS inside the enterprise

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use