Sadegh Aliakbary Sharif University of Technology Fall 2010.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
1 Inheritance and Polymorphism. 2 This section is not required material!!!!  A note about inheritance… It’s not normally covered in 101 It will be gone.
Inheritance Inheritance Reserved word protected Reserved word super
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
PACKAGES. PACKAGES IN JAVA A package is a collection of related classes and interfaces in Java Packages help in logical grouping of classes and interfaces.
More about classes and objects Classes in Visual Basic.NET.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
Inheritance COMP53 Sept Inheritance Inheritance allows us to define new classes by extending existing classes. A child class inherits all members.
CS 106 Introduction to Computer Science I 11 / 19 / 2007 Instructor: Michael Eckmann.
Unit 011 Inheritance Recall What Inheritance is About The extends Keyword The Object Class Overriding versus Overloading What is Actually Inherited? Single.
CS 2511 Fall UML Diagram Types  2 Main Types Structure Diagrams ○ Class Diagrams ○ Component Diagrams ○ Object Diagrams Behavior Diagrams ○
Sadegh Aliakbary Sharif University of Technology Fall 2010.
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
CPS Today’s topics Java Language Inheritance Upcoming Electric Circuits (not in text) Reading Great Ideas, Chapters 5.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Programming Pillars Introduction to Object- Oriented Programming.
Structured Programming Good for programming in the small Often doesn't scale up Limitations –Changes at top may affect lower-level algorithms –Code reuse.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Peyman Dodangeh Sharif University of Technology Fall 2014.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Inheritance and Access Control CS 162 (Summer 2009)
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Sadegh Aliakbary Sharif University of Technology Fall 2012.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Chapter 8 Specialization aka Inheritance. 2 Inheritance  Review of class relationships  Uses – One class uses the services of another class, either.
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
Coming up: Inheritance
More on Objects Mehdi Einali Advanced Programming in Java 1.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Peyman Dodangeh Sharif University of Technology Spring 2014.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
Inheritance in Java. Access Specifiers private keywordprivate keyword –Used for most instance variables –private variables and methods are accessible.
Peyman Dodangeh Sharif University of Technology Fall 2014.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
1 Inheritance and Polymorphism Chapter 11 Spring 2007 CS 101 Aaron Bloomfield.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Introduction to Object-oriented Programming
Advanced Programming in Java
Advanced Programming in Java
Road Map Inheritance Class hierarchy Overriding methods Constructors
Inheritance and Polymorphism
Advanced Programming in Java
Advanced Programming in Java
Inheritance, Polymorphism, and Interfaces. Oh My
Chapter 9: Polymorphism and Inheritance
Advanced Programming Behnam Hatami Fall 2017.
Code reuse through subtyping
انجمن جاواکاپ تقدیم می‌کند دوره برنامه‌نويسی جاوا
Final and Abstract Classes
Advanced Programming in Java
Programming in C# CHAPTER 5 & 6
Presentation transcript:

Sadegh Aliakbary Sharif University of Technology Fall 2010

Agenda Packages Inheritance Fall 2010Sharif University of Technology2

Package A package contains a group of classes Organized together under a single namespace Packages organize classes belonging to the same category or providing similar functionality A package provides a unique namespace for the types it contains Classes in one package has the same folder Packages may contain other packages Hierarchy of packages Fall 2010Sharif University of Technology3

Some famous java packages java.util java.lang java.io Fall 2010Sharif University of Technology4

Java Packages import keyword Class Qualified Name = package-name + class-name For example java.lang.String java.lang.Math double sqrt = Math.sqrt(123); java.util.Scanner java.awt.Event org.w3c.dom.events.Event Fall 2010Sharif University of Technology5

Using packages Fall 2010Sharif University of Technology6

java.lang java.lang is implicitly imported Fall 2010Sharif University of Technology7

Package Access Remember public and private access specifiers The default access has no keyword It is commonly referred to as package access and sometimes friendly Other classes in the current package have access to that member To classes outside of this package, the member appears to be private. Fall 2010Sharif University of Technology8

Write a packaged java project Lets write … Fall 2010Sharif University of Technology9

Fall 2010Sharif University of Technology10

Fall 2010Sharif University of Technology11

Fall 2010Sharif University of Technology12

UML Class Diagram Fall 2010Sharif University of Technology13

Fall 2010Sharif University of Technology14

Fall 2010Sharif University of Technology15

Fall 2010Sharif University of Technology16

UML Class Diagram Fall 2010Sharif University of Technology17

Inheritance Java offers inheritance As any object oriented programming language Code reuse extends keyword is-a relationship Fall 2010Sharif University of Technology18

Faculty & Staff Attributes of staff is inherited to Faculty Fall 2010Sharif University of Technology19

Shapes Example Shape is an abstract class The definition of some methods should be changed in sub-classes getArea() getPerimeter() Fall 2010Sharif University of Technology20

Terminology Class Rectangle is inherited from class Shape Rectangle is a subclass of Shape Rectangle is a child of Shape Rectangle is a derived class of Shape Shape is the super-class of Rectangle Shape is the parent of Rectangle Shape is the base-class of Rectangle Rectangle is-a Shape Fall 2010Sharif University of Technology21

Inheritance in java Every class is inherited from class Object Primitive-types are not objects Object class has some operations equals() toString() … Every class adds some operations And changes some operations toString() Fall 2010Sharif University of Technology22

Quiz! Fall 2010Sharif University of Technology23

Quiz Draw a UML class diagram for these Classes Person (name, phoneNumber) Student (average, entranceYear) MS Student (thesis title) Instructor (offeredCourses) Fall 2010Sharif University of Technology24

Fall 2010Sharif University of Technology25