CS200: Advanced OO in Java

Similar documents
Programming II (CS300)

Programming II (CS300)

Java Object Oriented Design. CSC207 Fall 2014

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Chapter 5 Object-Oriented Programming

Inheritance and Polymorphism. CS180 Fall 2007

ENCAPSULATION. private, public, scope and visibility rules. packages and package level access.

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

CMSC 132: Object-Oriented Programming II

Inheritance, and Polymorphism.

CS 251 Intermediate Programming Inheritance

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques. Version 03.s 2-1

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Programming Exercise 14: Inheritance and Polymorphism

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance?

Object-Oriented Programming Concepts

Inheritance and Polymorphism

Chapter 12. OOP: Creating Object-Oriented Programs The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

Polymorphism 2/12/2018. Which statement is correct about overriding private methods in the super class?

OVERRIDING. 7/11/2015 Budditha Hettige 82

Java Programming Lecture 7

Programming in C# Inheritance and Polymorphism

Chapter 6 Introduction to Defining Classes

CLASSES AND OBJECTS IN JAVA

Software Development. Modular Design and Algorithm Analysis

Object-Oriented Design

ITI Introduction to Computing II

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

PROGRAMMING LANGUAGE 2

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including:

Lesson 10. Work with Interfaces and Abstract Classes. Copyright all rights reserved

CS111: PROGRAMMING LANGUAGE II

CS-202 Introduction to Object Oriented Programming

CS1004: Intro to CS in Java, Spring 2005

Object Orientated Analysis and Design. Benjamin Kenwright

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

What is Inheritance?

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

Inheritance, Polymorphism, and Interfaces

CSCE3193: Programming Paradigms

CS111: PROGRAMMING LANGUAGE II

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

ITI Introduction to Computing II

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U

Chapter 10 Classes Continued. Fundamentals of Java

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017

Object Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes

IT101. Inheritance, Encapsulation, Polymorphism and Constructors

10. Java Classes. Classes - Technical. Example: Earthquake catalog. Classes - Conceptual

Understanding Inheritance and Interfaces

INHERITANCE. Spring 2019

Chapter 4 Defining Classes I

02 Features of C#, Part 1. Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211

CS313D: ADVANCED PROGRAMMING LANGUAGE

C++ Inheritance and Encapsulation

Inheritance and Polymorphism

QUESTIONS FOR AVERAGE BLOOMERS

Principles of Object Oriented Programming. Lecture 4

Understanding the Object Paradigm

Classes. Classes. Classes. Class Circle with methods. Class Circle with fields. Classes and Objects in Java. Introduce to classes and objects in Java.

Computer Science II (20073) Week 1: Review and Inheritance

Inheritance -- Introduction

Inheritance and Encapsulation. Amit Gupta

Chapter 14 Abstract Classes and Interfaces

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Goals of the Lecture OO Programming Principles

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Chapter 12. OOP: Creating Object- Oriented Programs. McGraw-Hill. Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.

Inheritance. Transitivity

Chapter 5: Classes and Objects in Depth. Information Hiding

Inheritance CSC 123 Fall 2018 Howard Rosenthal

C12a: The Object Superclass and Selected Methods

CMSC 132: Object-Oriented Programming II

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

C++ Important Questions with Answers

CSC9T4: Object Modelling, principles of OO design and implementation

Object-Oriented Concept

Object Oriented Programming

Inheritance and Polymorphism

Inheritance and Polymorphism

Data Abstraction. Hwansoo Han

More On inheritance. What you can do in subclass regarding methods:

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

CH. 2 OBJECT-ORIENTED PROGRAMMING

Object Oriented Programming. Java-Lecture 11 Polymorphism

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition

2.4 Structuring programs

Polymorphism. Arizona State University 1

Inheritance. Chapter 7. Chapter 7 1

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

Microsoft Visual Basic 2005: Reloaded

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Clarifying Roles. Jonathan Worthington German Perl Workshop 2007

Transcription:

Object Oriented Programming CS200: Advanced OO in Java n Programming paradigm using Objects : data structures consisting of data fields and methods together with their interaction. n Object? n Class? n Interface? n Package? 1 2 Basic Components a software bundle of related states (properties, or variables) and behavior (method) n State is stored in fields (variables in some programming languages) n Method exposes object s behavior. Methods Sound the alarm Silence the alarm Show the time Set the time Properties Time Alarm time Set the alarm Enable the alarm Basic Components n Class: Blueprint from which objects are created q Multiple Instances created from a class n Interface: A Contract between classes and the outside the world. q When a class implements an interface, it promises to provide the behavior published by that interface. 3 4 1

Basic Components Data Encapsulation n Package: a namespace for organizing classes and interfaces n An ability of an object to be a container (or capsule) for related properties and methods. q Preventing unexpected change or reuse of the content n Data hiding q Object can shield variables from external access. n Private variables n Public accessor and mutator methods 5 6 Data Encapsulation Inheritance public class Clock { private long time, alarm_time; private String serialno; public void settime(long _time){ time = _time; } public void setalarmtime(long_time){ alarm_time = _time; } public long gettime(){return time} public long getalarmtime(){return alarm_time} public void noticealarm(){ ring alarm } protected void set serialno(string _serialno){ } } 7 n The ability of a class to derive properties from a previously defined class. n Relationship among classes. n Enables reuse of software components q e.g., java.lang.object() q tostring(), notifyall(), equals(), etc. 8 2

Example: Inheritance Sports Watch clock Radio Clock Example: Inheritance cont. Public class SportsWatch extends Clock { private long start_time; private long end_time; public long getduration() { return end_time - start_time; } } 9 10 Overriding Methods Java Access Modifiers public class RadioClock { @override public void noticealarm(){ ring alarm turn_on_the_radio } } n Keywords: public, private,and protected n Control the visibility of the members of a class q Public members: used by anyone q Private members: used only by methods of the class q Protected members: used only by methods of the class, methods of other classes in the same package, and methods of the subclasses. q Members declared without an access modifier are available to methods of the class and methods of other classes in the same package. 11 12 3

Polymorphism n Having multiple forms n Ability to create a variable, or an object that has more than one form. Polymorphic method RadioClock myradioclock = new RadioClock(); Clock myclock = myradioclock; myclock.notifyalarm(); A: Clock B. RadioClock 13 14 Dynamic Binding Abstract n The version of a method notifyalarm() is decided at execution time. (not at compilation time) n A special kind of class that cannot be instantiated. n It allows only other classes to inherit from it. n It enforces certain hierarchies for all the subclasses 15 16 4

Interface Comparison-1 n An Interface is NOT a class. n An Interface has NO implementation inside. q Definitions of methods without body. Feature Interface Abstract Class Multiple inheritance A class may inherit several interfaces Default implementation Cannot provide any code Only one Can provide complete, default code and/or just the details that have to be overridden. Access Modifier Cannot have access modifiers. (everything is assumed as public) Can have it. 17 18 Comparison-2 Feature Interface Abstract Class Adding functionality (Versioning) For a new method, we have to track down all the implementations of the interface and define implementation for the new method For a new method, we can provide default implementation and all the existing code might work properly. Fields and Constants No fields can be defined in interfaces Fields and constants can be defined 19 5