SlideShare uma empresa Scribd logo
1 de 21
Baixar para ler offline
Object	
  Orientated	
  Programming	
  with	
  
                   Java	
  
               Jussi	
  Pohjolainen	
  
   Tampere	
  University	
  of	
  Applied	
  Sciences	
  
Object	
  Orientated	
  Concepts
                                           	
  
•    Class	
  
•    Object	
  
•    Inheritance	
  
•    Constructors	
  
•    Abstract	
  class	
  
•    Interface	
  
•    Polymorphism	
  
Class
                                            	
  
class Student {
   private String name;
   public Student(String name) {
      this.name = name;
   }
   public void setName(String name) {
      this.name = name
   }
   public void getName() {
      return name;
   }
}
CreaAng	
  objects
                                 	
  
Student jack = new Student(“Jack”);
Student bill = new Student(“Bill”);
System.out.println( jack.getName() );
System.out.println( bill.getName() );
Reference?	
  
Student jack = new Student(“Jack”);
Student bill = jack;
jack.setName(“Lisa”);
// What is the output?
System.out.println(bill.getName());
Reference	
  
•  In	
  Java,	
  every	
  object	
  is	
  passed	
  by	
  reference	
  
•  If	
  you	
  want	
  to	
  clone	
  a	
  object,	
  you	
  use	
  special	
  
   techniques	
  (later	
  on	
  the	
  material)	
  
Inheritance	
  
class Person {
   private String name;
  ...
}

class Student extends Person {
   private int id;
   ...
}
Constructors
                                        	
  
class Person {
   private String name;
   public Person() {
     System.out.println(“Person”);
   }
}
class Student extends Person {
   private int id;
   public Student() {
     System.out.println(“Student”);
   }
}
// What is the output?
Student s = new Student();
Default	
  Constructor
                                       	
  
•  If	
  programmer	
  does	
  not	
  define	
  a	
  constructor,	
  Java	
  
   creates	
  a	
  default	
  constructor:	
  
    class Person {
    }
    =>
    class Person {
       public Person() {
         super();
       }
    }
Default	
  Constructor
                                      	
  
class Person {
   private String name;
   public Person() {
    System.out.println(“Person”);
   }
}
class Student extends Person {
   private int id;
}
// What is the output?
Student s = new Student();
Default	
  Constructor	
  Problem	
  
class Person {
   private String name;
   public Person(String name) {
    System.out.println(“Person”);
   }
}
class Student extends Person {
   private int id;
}
// What is the output?
Student s = new Student();
Abstract	
  Class
                                         	
  
•  You	
  cannot	
  create	
  a	
  object	
  from	
  abstract	
  class	
  
•  Abstract	
  class	
  may	
  contain	
  abstract	
  method	
  
•  Abstract	
  method	
  is	
  a	
  method	
  declaraAon	
  which	
  
   must	
  be	
  implemented	
  in	
  inherited	
  classes	
  
Abstract	
  Class
                                      	
  
abstract class Graphic {
   abstract double calculateSurfaceArea();
}
class Circle extends Graphic {
   private int radius;
   double calculateSurfaceArea() {
    ...
   }
}
Abstract	
  Class
                                      	
  
abstract class A {
   abstract void m();
}
abstract class B extends A {
   // What is the implementation of the class B?
}
Interface	
  
•  Interface	
  is	
  a	
  abstract	
  class	
  that	
  contain	
  only	
  
   abstract	
  methods	
  
•  Interface	
  can	
  contain	
  also	
  public	
  staAc	
  final	
  
   variables	
  
•  Class	
  can	
  inherit	
  only	
  one	
  class,	
  but	
  it	
  can	
  
   implement	
  many	
  interfaces	
  
Interface	
  
interface class A {
   public void m();
}

class B implements A {
   public void m() {
    ...
   }
}
Polymorphism	
  
•  Declaring	
  a	
  object:	
  
     –  Graphic c;!
•  IniAalizing	
  the	
  object:	
  
     –  c = new Graphic();!
•  This	
  is	
  also	
  possible:	
  
     –  c = new Circle();!
     –  c = new Rect();!
•  If	
  Circle and	
  Rect are	
  inherited	
  from	
  Graphic!
Polymorphism	
  
class Polymorphism {
   public static void main(String [] args) {
    // What are the possible objects to be passed?
    method(??)
   }
   public static void method(Graphic c) {
    ...
   }
}
Polymorphism	
  
interface R {
   ...
}
class Polymorphism {
   public static void main(String [] args) {
    // What are the possible objects to be passed?
    method(??)
   }
   public static void method(R r) {
    ...
   }
}
Cloning	
  
class Person implements Cloneable {
   private name;
   public Person(String name) {
    this.name = name;
   }
   public Object clone() {
    return new Person(this.name);
   }
}
Person a = new Person(“jack”);
Person b = a.clone();
Equals
                                 	
  
// What happens here?
Student jack1 = new Student(“Jack”);
Student jack2 = new Student(“Jack”);
System.out.println( jack1 == jack2 ); // true or false?
System.out.println( jack1.equals(jack2) ); // ?

Mais conteúdo relacionado

Mais procurados

Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
backdoor
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
Jussi Pohjolainen
 

Mais procurados (20)

ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
Pi j3.2 polymorphism
Pi j3.2 polymorphismPi j3.2 polymorphism
Pi j3.2 polymorphism
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Best Core Java Training In Bangalore
Best Core Java Training In BangaloreBest Core Java Training In Bangalore
Best Core Java Training In Bangalore
 
‫Object Oriented Programming_Lecture 3
‫Object Oriented Programming_Lecture 3‫Object Oriented Programming_Lecture 3
‫Object Oriented Programming_Lecture 3
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Core java
Core javaCore java
Core java
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Class or Object
Class or ObjectClass or Object
Class or Object
 
Object and class
Object and classObject and class
Object and class
 
Classes and objects in java
Classes and objects in javaClasses and objects in java
Classes and objects in java
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
Classes&objects
Classes&objectsClasses&objects
Classes&objects
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objects
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - Inheritance
 
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and Object
 

Destaque

Object oriented fundamentals_in_java
Object oriented fundamentals_in_javaObject oriented fundamentals_in_java
Object oriented fundamentals_in_java
Self
 
OOP programming
OOP programmingOOP programming
OOP programming
anhdbh
 
Object Oriented Design in Software Engineering SE12
Object Oriented Design in Software Engineering SE12Object Oriented Design in Software Engineering SE12
Object Oriented Design in Software Engineering SE12
koolkampus
 

Destaque (17)

Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1
 
Applying OO Concepts
Applying OO ConceptsApplying OO Concepts
Applying OO Concepts
 
JavaYDL15
JavaYDL15JavaYDL15
JavaYDL15
 
Itt1 sd uml and oo
Itt1 sd uml and ooItt1 sd uml and oo
Itt1 sd uml and oo
 
Object oriented fundamentals_in_java
Object oriented fundamentals_in_javaObject oriented fundamentals_in_java
Object oriented fundamentals_in_java
 
OO & UML
OO & UMLOO & UML
OO & UML
 
Introduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphereIntroduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphere
 
Unified modelling language (UML)
Unified modelling language (UML)Unified modelling language (UML)
Unified modelling language (UML)
 
OOP programming
OOP programmingOOP programming
OOP programming
 
OO Development 3 - Models And UML
OO Development 3 - Models And UMLOO Development 3 - Models And UML
OO Development 3 - Models And UML
 
Module 3 Object Oriented Data Models Object Oriented notations
Module 3  Object Oriented Data Models Object Oriented notationsModule 3  Object Oriented Data Models Object Oriented notations
Module 3 Object Oriented Data Models Object Oriented notations
 
Packaes & interfaces
Packaes & interfacesPackaes & interfaces
Packaes & interfaces
 
What does OOP stand for?
What does OOP stand for?What does OOP stand for?
What does OOP stand for?
 
Uml
UmlUml
Uml
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
Object Oriented Design in Software Engineering SE12
Object Oriented Design in Software Engineering SE12Object Oriented Design in Software Engineering SE12
Object Oriented Design in Software Engineering SE12
 
Objects & OO Thinking for Java
Objects & OO Thinking for JavaObjects & OO Thinking for Java
Objects & OO Thinking for Java
 

Semelhante a Java OO Revisited

C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritance
shatha00
 
Hello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfHello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdf
irshadkumar3
 

Semelhante a Java OO Revisited (20)

Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 
Java Concepts
Java ConceptsJava Concepts
Java Concepts
 
Core Java
Core JavaCore Java
Core Java
 
Core java concepts
Core java concepts Core java concepts
Core java concepts
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
11slide.ppt
11slide.ppt11slide.ppt
11slide.ppt
 
Java Methods
Java MethodsJava Methods
Java Methods
 
11slide
11slide11slide
11slide
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
 
C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritance
 
Hello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfHello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdf
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
8 polymorphism
8 polymorphism8 polymorphism
8 polymorphism
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
Chapter 6 OOP (Revision)
Chapter 6 OOP (Revision)Chapter 6 OOP (Revision)
Chapter 6 OOP (Revision)
 
Sonu wiziq
Sonu wiziqSonu wiziq
Sonu wiziq
 
core java
core javacore java
core java
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Concepts
 

Mais de Jussi Pohjolainen

Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Jussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
Jussi Pohjolainen
 

Mais de Jussi Pohjolainen (20)

Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

Java OO Revisited

  • 1. Object  Orientated  Programming  with   Java   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  • 2. Object  Orientated  Concepts   •  Class   •  Object   •  Inheritance   •  Constructors   •  Abstract  class   •  Interface   •  Polymorphism  
  • 3. Class   class Student { private String name; public Student(String name) { this.name = name; } public void setName(String name) { this.name = name } public void getName() { return name; } }
  • 4. CreaAng  objects   Student jack = new Student(“Jack”); Student bill = new Student(“Bill”); System.out.println( jack.getName() ); System.out.println( bill.getName() );
  • 5. Reference?   Student jack = new Student(“Jack”); Student bill = jack; jack.setName(“Lisa”); // What is the output? System.out.println(bill.getName());
  • 6. Reference   •  In  Java,  every  object  is  passed  by  reference   •  If  you  want  to  clone  a  object,  you  use  special   techniques  (later  on  the  material)  
  • 7. Inheritance   class Person { private String name; ... } class Student extends Person { private int id; ... }
  • 8. Constructors   class Person { private String name; public Person() { System.out.println(“Person”); } } class Student extends Person { private int id; public Student() { System.out.println(“Student”); } } // What is the output? Student s = new Student();
  • 9. Default  Constructor   •  If  programmer  does  not  define  a  constructor,  Java   creates  a  default  constructor:   class Person { } => class Person { public Person() { super(); } }
  • 10. Default  Constructor   class Person { private String name; public Person() { System.out.println(“Person”); } } class Student extends Person { private int id; } // What is the output? Student s = new Student();
  • 11. Default  Constructor  Problem   class Person { private String name; public Person(String name) { System.out.println(“Person”); } } class Student extends Person { private int id; } // What is the output? Student s = new Student();
  • 12. Abstract  Class   •  You  cannot  create  a  object  from  abstract  class   •  Abstract  class  may  contain  abstract  method   •  Abstract  method  is  a  method  declaraAon  which   must  be  implemented  in  inherited  classes  
  • 13. Abstract  Class   abstract class Graphic { abstract double calculateSurfaceArea(); } class Circle extends Graphic { private int radius; double calculateSurfaceArea() { ... } }
  • 14. Abstract  Class   abstract class A { abstract void m(); } abstract class B extends A { // What is the implementation of the class B? }
  • 15. Interface   •  Interface  is  a  abstract  class  that  contain  only   abstract  methods   •  Interface  can  contain  also  public  staAc  final   variables   •  Class  can  inherit  only  one  class,  but  it  can   implement  many  interfaces  
  • 16. Interface   interface class A { public void m(); } class B implements A { public void m() { ... } }
  • 17. Polymorphism   •  Declaring  a  object:   –  Graphic c;! •  IniAalizing  the  object:   –  c = new Graphic();! •  This  is  also  possible:   –  c = new Circle();! –  c = new Rect();! •  If  Circle and  Rect are  inherited  from  Graphic!
  • 18. Polymorphism   class Polymorphism { public static void main(String [] args) { // What are the possible objects to be passed? method(??) } public static void method(Graphic c) { ... } }
  • 19. Polymorphism   interface R { ... } class Polymorphism { public static void main(String [] args) { // What are the possible objects to be passed? method(??) } public static void method(R r) { ... } }
  • 20. Cloning   class Person implements Cloneable { private name; public Person(String name) { this.name = name; } public Object clone() { return new Person(this.name); } } Person a = new Person(“jack”); Person b = a.clone();
  • 21. Equals   // What happens here? Student jack1 = new Student(“Jack”); Student jack2 = new Student(“Jack”); System.out.println( jack1 == jack2 ); // true or false? System.out.println( jack1.equals(jack2) ); // ?