CS260: Object Oriented Programming Inheritance - January 26, 2016 - - PowerPoint PPT Presentation

cs260 object oriented programming
SMART_READER_LITE
LIVE PREVIEW

CS260: Object Oriented Programming Inheritance - January 26, 2016 - - PowerPoint PPT Presentation

CS260: Object Oriented Programming Inheritance - January 26, 2016 Quiz next time... UML Class Diagrams Overview Inheritance hw2 Questions Super extra credit example? Quiz next time... 1. What is an Object? a.


slide-1
SLIDE 1

CS260: Object Oriented Programming

Inheritance - January 26, 2016

slide-2
SLIDE 2

Overview

  • Quiz next time...
  • UML Class Diagrams
  • Inheritance
  • hw2 Questions

○ Super extra credit example?

slide-3
SLIDE 3

Quiz next time...

1. What is an Object?

a. Related variables and functions, encapsulated in a single type

2. What are the two parts of an Object?

a. State b. Behavior

3. What is a Class

a. A blueprint for creating Objects

slide-4
SLIDE 4

Quiz next time...

4. What is a method?

a. A class function

5. What is a field?

a. A class variable

6. What is a constructor?

a. A function with the same name as it’s containing class that creates and sets up Objects

slide-5
SLIDE 5

Quiz next time...

7. Classes

a. What does a class declaration look like?

public class ClassNameHere { //this is where fields go ClassNameHere(){ //this is where we set up the class } //this is where methods go }

slide-6
SLIDE 6

UML

  • Unified Modelling Language

○ Developed 1994 - 1995 ○ Grady Booch, Ivar Jacobson, James Rumbaugh ○ Standard software notations

  • Diagrams

○ Class Diagram ○ Object Diagram ○ Use Case Diagram

  • Wikipedia Link - https://en.wikipedia.org/wiki/Unified_Modeling_Language
slide-7
SLIDE 7

UML Class Diagrams

  • Class Name
  • State - Fields
  • Behavior - Methods
slide-8
SLIDE 8

UML Class Diagram Example

slide-9
SLIDE 9

OOP - Inheritance

  • What is inheritance?

○ A way of deriving specific Classes from other, more general Classes ○ Allows you to reuse code from a more general Class

  • What does inheritance look like?

○ Standard Class declaration but with “extends” keyword

public class ChildClass extends ParentClass { //this is where fields go ChildClass(){ //this is where we set up the class } //this is where methods go }

slide-10
SLIDE 10

Inheritance Example

slide-11
SLIDE 11

On your own… (not homework)

  • Look at:

○ Inheritance on official Java Docs - https://docs.oracle. com/javase/tutorial/java/IandI/subclasses.html