Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sadegh Aliakbary Sharif University of Technology Fall 2010.

Similar presentations


Presentation on theme: "Sadegh Aliakbary Sharif University of Technology Fall 2010."— Presentation transcript:

1 Sadegh Aliakbary Sharif University of Technology Fall 2010

2 Agenda Packages Inheritance Fall 2010Sharif University of Technology2

3 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

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

5 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

6 Using packages Fall 2010Sharif University of Technology6

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

8 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

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

10 Fall 2010Sharif University of Technology10

11 Fall 2010Sharif University of Technology11

12 Fall 2010Sharif University of Technology12

13 UML Class Diagram Fall 2010Sharif University of Technology13

14 Fall 2010Sharif University of Technology14

15 Fall 2010Sharif University of Technology15

16 Fall 2010Sharif University of Technology16

17 UML Class Diagram Fall 2010Sharif University of Technology17

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

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

20 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

21 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

22 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

23 Quiz! Fall 2010Sharif University of Technology23

24 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

25 Fall 2010Sharif University of Technology25


Download ppt "Sadegh Aliakbary Sharif University of Technology Fall 2010."

Similar presentations


Ads by Google