fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. SomeObject obj1 = new SomeObject(1, "Lorem ipsum");
  13. SomeObject obj2 = (SomeObject) obj1.clone();
  14.  
  15. System.out.println("Object 1: " + obj1);
  16. System.out.println("Object 2: " + obj2);
  17.  
  18. System.out.println("São iguais? " + obj1.equals(obj2));
  19. }
  20. }
  21.  
  22. class SomeObject implements Cloneable{
  23.  
  24. private int identifier;
  25. private String someDescription;
  26.  
  27. public SomeObject() {
  28.  
  29. }
  30.  
  31. @Override
  32. protected Object clone() throws CloneNotSupportedException {
  33. // TODO Auto-generated method stub
  34. return super.clone();
  35. }
  36.  
  37.  
  38. public SomeObject(int identifier, String someDescription) {
  39. super();
  40. this.identifier = identifier;
  41. this.someDescription = someDescription;
  42. }
  43.  
  44.  
  45.  
  46. public int getIdentifier() {
  47. return identifier;
  48. }
  49.  
  50. public void setIdentifier(int identifier) {
  51. this.identifier = identifier;
  52. }
  53.  
  54. public String getSomeDescription() {
  55. return someDescription;
  56. }
  57.  
  58. public void setSomeDescription(String someDescription) {
  59. this.someDescription = someDescription;
  60. }
  61.  
  62. @Override
  63. public String toString() {
  64. return "[" + this.identifier + " - " + this.someDescription + "]";
  65. }
  66.  
  67. }
  68.  
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
Object 1: [1 - Lorem ipsum]
Object 2: [1 - Lorem ipsum]
São iguais? false