Does not implement clone() method! public class Bar { … public Object clone() { … } Does not implement Cloneable interface!

Slides:



Advertisements
Similar presentations
Uguaglianza equals() e clone(). Fondamenti di Java Uguali o identici?
Advertisements

Clonazione La clonazione... Ovvero: come costruire una copia (probabilmente che ritorni true su equals?)
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Interfaces (Part II) Course Lecture Slides 28 June 2010 A picture is.
Lecture 5: Interfaces.
CSC 243 – Java Programming, Spring 2013 March 26, 2013 Week 8, java.lang.Clonable & java.io.Serializable Interfaces.
Chapter 15: Generic Methods, Classes, and Array-Based Lists
Inheritance Lakshmish Ramaswamy. Example A Rectangle class with area method A Circle class with area method Array containing references to circles & rectangles.
Effective Java, Chapter 3: Methods Common to All Objects.
Chapter 3 Collection Classes Anshuman Razdan Department of Engineering
Tirgul 1 Today’s subjects: –First programming exercise. –Java reminder & completions : reference data types, cloning, inner classes, packages. –Short reminder.
1 More on Inheritance Overview l Object: The father of all classes l Casting and Classes l Object Cloning l Importance of Cloning.
Mutable, Immutable, and Cloneable Objects Chapter 15.
CSE 11 February 6, © 2003 Walter Savitch These slides are for the exclusive use of students in CSE 11 at UCSD, Winter quarter They may not.
Interfaces. In this class, we will cover: What an interface is Why you would use an interface Creating an interface Using an interface Cloning an object.
1 Java Object Model Part 2: the Object class. 2 Object class Superclass for all Java classes Any class without explicit extends clause is a direct subclass.
CST Razdan et al Razdan with contribution from others 1 Chapter 6 Stacks Anshuman Razdan Div of Computing.
Chapter 4 Linked Lists Anshuman Razdan Div of Computing Studies
Tirgul 1 Today’s subject - Java reminders and additions: –Inner classes –Packages –I/O streams –Command Line Arguments –Primitive and Reference Data Types.
Mutable, Immutable, and Cloneable Objects Chapter 15 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Lecture 18 Review the difference between abstract classes and interfaces The Cloneable interface Shallow and deep copies The ActionListener interface,
Interface. Interface interface the public methods of the classWhen you talk about the interface of a class you typically mean the public methods of the.
Cloning.  Goal: Create an identical, independent copy of an object  Override the method (every class inherits clone() from class Object) public Object.
Interfaces and Inner Classes. What is an Interface?  What is “presented to the user”?  The public part of a class?  What is the substance of an interface?
16-Aug-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming in Java Topic : Interfaces, Copying/Cloning,
CMSC 132 Week2 Lab1 Comparable vs Comparator clone() finalize()
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Problem of the Day  What is the smallest positive integer that cannot be defined in less than twenty-five syllables?
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns II.
Abstract and Nested Classes
Predefined Classes in Java Ellen Walker CPSC 201 Data Structures Hiram College.
Implications of Inheritance COMP204, Bernhard Pfahringer.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 1 Chapter 13 Abstract Classes and Interfaces.
Advanced Java Programming CS 537 – Data Structures and Algorithms.
 Definition: Accessing child class methods through a parent object  Example: Child class overrides default parent class methods  Example: Child class.
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
Advanced Programming Rabie A. Ramadan vpro/ Lecture 4.
Object Oriented Programming Java 1 Some Notes on Cloning, Packages and Visibility Notes from Bruce Eckel’s “Thinking in Java” and “Just Java” by.
Effective Java: Methods Common to All Objects SWE 619: Fall 2008 Paul Ammann.
TreeBag a BST implementation. Example class - TreeBag  remember Bag?  collection of items, order does not matter  repeated items allowed public void.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
The Prototype Pattern (Creational) ©SoftMoore ConsultingSlide 1.
CS 61B Data Structures and Programming Methodology July 8, 2008 David Sun.
SHEEP CLONING Paley Li, Nicholas Cameron, and James Noble 1.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Interfaces (Part II) Course Lecture Slides 28 June 2010 “A picture is.
FIT Objectives By the end of this lecture, students should: understand the role of constructors understand how non-default constructors are.
Carnegie Mellon University, Graduate School of Industrial Administration 1 Initialization and Cloning Slides adapted from course text “Thinking in Java”
Classes Revisited Chapter 8.
1 Creational Design Patterns CSC 335: Object-Oriented Programming and Design.
PROTOTYPE. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract factory.
3/11/2016ITK 2751 String String class objects are immutable public String s1,s2; s1 = "This is a String!!"; s2 = s1; s1:FFFF218C This is a String!! s2:FFFF218C.
1 clone() Defined in Object Creates an identical copy –Copies pointers to fields (does not copy fields of fields) –Makes a shallow copy if the object’s.
C11, Implications of Inheritance
Chapter 7: Cloning and RTTI
Polymorphism 2nd Lecture
Chengyu Sun California State University, Los Angeles
Chapter 8 Classes and Objects
CIS3023: Programming Fundamentals for CIS Majors II
CSE 331 Cloning objects slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Lecture 4: Interface Design
null, true, and false are also reserved.
Programming in Java Lecture 11: ArrayList
Chengyu Sun California State University, Los Angeles
Prototype Pattern 1.
Interfaces.
CS520 Web Programming Spring – Aspect Oriented Programming
CS 112 Programming 2 Lecture 02 Abstract Classes & Interfaces (2)
Clonazione La clonazione... Ovvero: come costruire una copia
Sampath Kumar S Assistant Professor, SECE
Inheritance Lakshmish Ramaswamy.
Presentation transcript:

Does not implement clone() method! public class Bar { … public Object clone() { … } Does not implement Cloneable interface!

Returns null! At least, throw CloneNotSupportedException instead!

Never calls super.clone()!

Foo public class Bar { Foo f; … public Object clone() { … clone.f = (Foo) f.clone(); … } In Java 5, use covariant return type!

Fields selected for deep copy

Complete240 clone() methods Consistent class annotation 189 classes do not implement interface 14 do not implement clone() method Returning nullNo violations Not calling super.clone()237 violations! Object as return typeIn all 240 cases

public class Bar extends Foo { public Object clone() { Bar clone = super.clone(); … return clone; }