Classes, Objects, and OOP in Java. June 16, 2017

Similar documents
OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

What is Inheritance?

C++ Important Questions with Answers

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

CPS 506 Comparative Programming Languages. Programming Language

Java Object Oriented Design. CSC207 Fall 2014

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

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

Introduction to Programming Using Java (98-388)

Object Orientated Analysis and Design. Benjamin Kenwright

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

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

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

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Chapter 5 Object-Oriented Programming

Arrays Classes & Methods, Inheritance

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Data Structure. Recitation III

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Object Oriented Programming. Solved MCQs - Part 2

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

Object oriented programming Concepts

COP 3330 Final Exam Review

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Programming Exercise 14: Inheritance and Polymorphism

CS-202 Introduction to Object Oriented Programming

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

JAVA MOCK TEST JAVA MOCK TEST II

CSSE 220. Interfaces and Polymorphism. Check out Interfaces from SVN

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.

Introduction to Inheritance

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

Programming overview

STRUCTURING OF PROGRAM

Object Oriented Paradigm

1 Shyam sir JAVA Notes

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Programming II (CS300)

Inheritance and Interfaces

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

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

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

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Scope. Chapter Ten Modern Programming Languages 1

CSE 307: Principles of Programming Languages

CS121/IS223. Object Reference Variables. Dr Olly Gotel

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

JAVA: A Primer. By: Amrita Rajagopal

Media Computation. Lecture 16.1, December 8, 2008 Steve Harrison

Chapter 2: Java OOP I

Data Structures (list, dictionary, tuples, sets, strings)

ITI Introduction to Computing II

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

What are the characteristics of Object Oriented programming language?

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Notes on Chapter Three

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

Fast Introduction to Object Oriented Programming and C++

CMSC 132: Object-Oriented Programming II

C++ Programming: Introduction to C++ and OOP (Object Oriented Programming)

Data Abstraction. Hwansoo Han

Overriding המחלקה למדעי המחשב עזאם מרעי אוניברסיטת בן-גוריון

Programming II (CS300)

Chapter 15: Object Oriented Programming

9 Working with the Java Class Library

Inheritance and Polymorphism

ITI Introduction to Computing II

COSC 121: Computer Programming II. Dr. Bowen Hui University of Bri?sh Columbia Okanagan

Lecture 15: Object-Oriented Programming

QUIZ. How could we disable the automatic creation of copyconstructors

IT101. Inheritance, Encapsulation, Polymorphism and Constructors

Lecture 10. Overriding & Casting About

Review: Object Diagrams for Inheritance. Type Conformance. Inheritance Structures. Car. Vehicle. Truck. Vehicle. conforms to Object

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

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

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

Object-Oriented Programming Concepts

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Programming in C# Inheritance and Polymorphism

CGS 2405 Advanced Programming with C++ Course Justification

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING

Concepts of Object Oriented Programming

Object Oriented Programming

Object Oriented Programming

CMSC 330: Organization of Programming Languages

CSC Java Programming, Fall Java Data Types and Control Constructs

Crash Course Review Only. Please use online Jasmit Singh 2

CSE 431S Type Checking. Washington University Spring 2013

CSEN401 Computer Programming Lab. Topics: Object Oriented Features: Abstraction and Polymorphism

QUIZ. How could we disable the automatic creation of copyconstructors

1. Write two major differences between Object-oriented programming and procedural programming?

MORE OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 4 09/01/2011

More OO Fundamentals. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 4 09/11/2012

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

EECS168 Exam 3 Review

F1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept

Transcription:

Classes, Objects, and OOP in Java June 16, 2017

Which is a Class in the below code? Mario itsame = new Mario( Red Hat? ); A. Mario B. itsame C. new D. Red Hat?

Whats the difference? int vs. Integer A. One is type, the other is not B. One is a reference, the other is a Class C. One is more efficient than the other D. One is Java, the other is C

Whats the difference? char[] lang = { j, a, v, a }; String lang = java ; A. One is a reference, one is a primitive B. One is Unicode, the other is ASCII C. One is an array, the other is type String D. One is type char, the others of type String

Which evaluate to True? String first = First ; String tied = First ; A. first == tied B. first.isequal(tied) C. first.getclass() == tied.getclass() D. first == String && second == String

Which are Synonyms? A. Object and Instance B. Type and Class C. int and Integer D. static and final

Which are Knowable? GIVEN _only_ this information: 1. getpurposeoflife is a static method 2. DanceGod.getPurposeOfLife() is valid A. getpurposeoflife() returns an object B. DanceGod is final C. getpurposeoflife is public D. DanceGod is a class

Which is a true difference between functions in C, and methods in Java? A. Functions do not declare their return type, methods do B. Methods in java can take fewer arguments that functions in C C. Methods in java are tied to classes, functions in C are tied to structs. D. Java allows named parameters, C does not

What is knowable about visibility public class PublicClass { bool ispublic = true; } A. Syntax error B. is public is visible only to static methods C. ispublic is visible to other objects D. ispublic cannot be changed

What is a Constructor A. An uncommon feature from older versions of java B. How code configures functionality to trigger when an object is constructed C. How Java determines the type of the object to be constructed D. A class that creates other classes

Done!

Housekeeping Homework 1 has passed Homework 2 over the weekend Course topics / schedule Class reworking

OOP and Java Goals History of OOP OOP in Java

Why OOP? (Goals) Text Book Encapsulation (Review today) Polymorphism (Most of today) Inheritance (Today and Monday) \_( ツ )_/

Problem One Functions and Data struct band { char * name; person members[10]; int num_members; }; person band_tallest_member(band *a_band) { } // Adding a new member? // Wanting to do so something else with a band (ex, if we // want to test if MF Doom was in the band) // Default values for bands?

Encapsulation Binding together functionality and data Hiding the inner workings of code Prevent boiler plate, setup code Integrity

Problem Two Similar Data struct band { char * name; person members[10]; int num_members; }; person band_tallest_member(band *a_band) { } struct company { char * name; person members[10]; int num_members; int age; }; // Finding tallest member of the company?

Polymorphism Abstracting over similar things Maintaining type information From a consumer / client / user perspective

Problem Three Similar Functionality on Data struct band { char * name; person members[10]; int num_members; (some code to calculate tallest person) }; struct company { char * name; person members[10]; int num_members; int age; (some code to calculate tallest person) }; // How to not write the same thing twice

Inheritance Defining type hierarchies Shoving functionality into parent types Common, but not required, in OOP

Java and OOP Class is everything Types Functionality taxonomy Data taxonomy Namespaces Functions (sorta ) Quirk of Java

Encapsulation in Java Define a class Define some data the class Define some functionality that uses that class

Encapsulation in Java struct band { char * name; person members[10]; int num_members; }; person band_tallest_member(band *a_band) { }

Encapsulation.java

Encapsulation in Java this makes things unambiguous public / private controls access constructors can create defaults Explicit is better than implicit

Polymorphism in Java Class hierarchy Interfaces (later) Generics (even later)

Class Hierarchy Band -gettallestmember Company -gettallestmember -getcompanyage

Class Hierarchy PeopleDoingThingsTogether Band -gettallestmember Company -gettallestmember -getcompanyage

Polymorphism.java

Inheritance in Java Sharing code between types Check child classes first, then parents, then parents of parents, then extends"

Class Hierarchy PeopleDoingThingsTogether Band -gettallestmember Company -gettallestmember -getcompanyage

Class Hierarchy PeopleDoingThingsTogether -gettallestmember Band Company -getcompanyage

Class Hierarchy PeopleDoingThingsTogether -gettallestmember Band Company -getcompanyage -gettallestmember

Class Hierarchy PeopleDoingThingsTogether -gettallestmember Band ReasonableCompanies Company -getcompanyage PettyCompanies -gettallestmember

Inheritance in Java Start with most specific class Keep looking up until we find a match then stop `MethodNotFoundException` or compiler error if no chance

Further Code Sharing Child methods will often be similar We want D.R.Y. code How to slightly" change parent implementations super and this Abstract

InheritanceSuper.java

Java OO Particularities Arguments are part of a method s signature Disambiguation happens at runtime Static / final / scoped classes etc.

Programming, Step 1 Groups Brainstorm class hierarchy Three tiers deep, at least 4 types Examples of three methods, at least one for each level of hierarchy

Programming, Step 2 Describe a class hierarchy Should have at least the following classes Animals Cats Lizards ColdBlooded WarmBlooded Dogs Food needs

Programming, Step 3 Implement simple program that sorts user provided animals into bins, depending on their needs getname() main(string[] args) Print out summary

Wrap Up Coding good? Slides better? Homework 2 Reading for Monday Office hours now!