The Artima Developer Community
Sponsored Link

Java Buzz Forum
Friday Java Quiz: Know Your java.lang.Object Class

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.
Friday Java Quiz: Know Your java.lang.Object Class Posted: Jan 4, 2008 9:03 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Weiqi Gao.
Original Post: Friday Java Quiz: Know Your java.lang.Object Class
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

Warm Up Q: Without the help of your IDE or looking at the Javadoc, list all methods of the java.lang.Object class.

Q: Will the following program compile? Run? Print anything? If so, what?

public class Foo implements Cloneable {
  private int i;

  public Foo(int i) {
    this.i = i;
  }

  public int getI() {
    return i;
  }

  public static void main(String[] args) throws Throwable {
    Foo foo1 = new Foo(1024);
    Foo foo2 = (Foo) foo1.clone();
    System.out.println(foo2.getI());
  }
}

Follow Up Q 1: How would things change if the following method is added:

  public Object clone() throws CloneNotSupportedException {
    return super.clone();
  }

Follow Up Q 2: How about this?

  public Object clone() throws CloneNotSupportedException {
    Foo clone = (Foo) super.clone();
    clone.i = this.i;
  }

Again, no actually running the compiler, etc., etc., ...

Read: Friday Java Quiz: Know Your java.lang.Object Class

Topic: Links for 2007-12-21 [del.icio.us] Previous Topic   Next Topic Topic: Song: Witty Take on Spam - I've Got Mail

Sponsored Links



Google
  Web Artima.com   

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