1 Abstract Class and Packages from Chapter 9 Lecture.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

Object-Oriented Programming Session 9 Course : T Programming Language Concept Year : February 2011.
2006 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
Advanced Piloting Cruise Plot.
Final and Abstract Classes
1 Inheritance Classes and Subclasses Or Extending a Class.
1 Packages: Putting Classes Together. 2 Introduction The main feature of OOP is its ability to support the reuse of code: Extending the classes (via inheritance)
Copyright © 2002 Pearson Education, Inc. Slide 1.
Chapter 6 Structures and Classes. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-2 Learning Objectives Structures Structure types Structures.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
UNITED NATIONS Shipment Details Report – January 2006.
12 Copyright © 2005, Oracle. All rights reserved. Structuring Code Using Abstract Classes and Interfaces.
7 Copyright © 2005, Oracle. All rights reserved. Creating Classes and Objects.
10 Copyright © 2005, Oracle. All rights reserved. Reusing Code with Inheritance and Polymorphism.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Exit a Customer Chapter 8. Exit a Customer 8-2 Objectives Perform exit summary process consisting of the following steps: Review service records Close.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Addition Facts
Year 6 mental test 10 second questions
2010 fotografiert von Jürgen Roßberg © Fr 1 Sa 2 So 3 Mo 4 Di 5 Mi 6 Do 7 Fr 8 Sa 9 So 10 Mo 11 Di 12 Mi 13 Do 14 Fr 15 Sa 16 So 17 Mo 18 Di 19.
ZMQS ZMQS
Solve Multi-step Equations
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
ITEC200 Week04 Lists and the Collection Interface.
ABC Technology Project
By Waqas Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most.
1 Undirected Breadth First Search F A BCG DE H 2 F A BCG DE H Queue: A get Undiscovered Fringe Finished Active 0 distance from A visit(A)
Green Eggs and Ham.
VOORBLAD.
15. Oktober Oktober Oktober 2012.
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
BIOLOGY AUGUST 2013 OPENING ASSIGNMENTS. AUGUST 7, 2013  Question goes here!
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
© 2012 National Heart Foundation of Australia. Slide 2.
1 Chapter 4 The while loop and boolean operators Samuel Marateck ©2010.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Chapter 5 Test Review Sections 5-1 through 5-4.
Addition 1’s to 20.
25 seconds left…...
H to shape fully developed personality to shape fully developed personality for successful application in life for successful.
Januar MDMDFSSMDMDFSSS
Week 1.
Analyzing Genes and Genomes
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Intracellular Compartments and Transport
PSSA Preparation.
Immunobiology: The Immune System in Health & Disease Sixth Edition
Chapter 11 Component-Level Design
Essential Cell Biology
1 Chapter 13 Nuclear Magnetic Resonance Spectroscopy.
Immunobiology: The Immune System in Health & Disease Sixth Edition
Energy Generation in Mitochondria and Chlorplasts
Abstract Class, Packages and interface from Chapter 9
Chapter 9: Using Classes and Objects. Understanding Class Concepts Types of classes – Classes that are only application programs with a Main() method.
Presentation transcript:

1 Abstract Class and Packages from Chapter 9 Lecture

2 Review Abstract classes Using final with inheritance Packages Access protection Importing packages

3 Abstract Classes Sometimes, we want to define a superclass that declares the structure of a abstraction with a complete implementation of every method. That is, we want to create a superclass that only defines a generalised form that will be shared by all of its subclasses.

4 More about Abstract Classes The main purpose of an abstract class is to define a common interface for it's subclasses to which some or all implementation is deferred. Abstract classes may be used in designing a family of related subclasses. The general form is: abstract type name (parameter-list)

5 Example – page 217

6 Explanation In object-oriented programming, we want to model an abstract concept without being able to create an instance of it. Here, class A defines an abstract class callme() {This class also supports a concrete method callme1(). } callme() is implemented in Class B.

7 Final Final with inheritance has three uses. First, it can be used to create the equivalent of a named constant Secondly, to apply final to prevent overriding Thirdly, to use final to prevent inheritance

8 Using final to prevent overriding Overriding is one of java ’ s most powerful features, there will be times when we will want to prevent it from occurring. To disallow a method from being overridden, we specify final as a modifier at the start of its declaration.

9 Example – with a compilation error Because show() is declared as final, it cannot be overridden.

10 Using final to prevent inheritance Sometimes, we want to prevent a class from being inherited. To do this, we can precede the class declaration with final. Declaring a class as final implies that all of its methods as final.

11 Example – with a compilation error

12 Package Packages are one of the basic components of a Java Program. In general, a Java source can contain any of the following: A single package statement Any number of import statements A single public class declaration Any number of classes private to the package

13 Create a package To create a package is easy. The user simply includes a package command as the first statement in a Java source file. The package statement defines a name space in which classes are package, which has no name. The format is: package pkg; Name of the package (directory), not class

14 Package Hierarchy The package hierarch is: package java.awt.image; It access the package in java/awt/image

15 Manual Method Example (1) Make a directory called YourPackage under your current directory mkdir YourPackage Use a notepad to create a file as follows and put it under the directory of YourPackage

16 Example (2) Compile it

17 Example (3)

18 More Example (1) Create a file on left-hand side. Put it into a directory called Mypack Compile it

19 More Example (2)

Creating Packages Using Eclipse 20

Snap for Creating Package 21

Viewing the newly created Package 22

23 Access Protection In Java, there are at least three control mechanism. private, public and protected Package adds another dimension to access control. Java provides many levels of protection over the visibility of variables and methods within classes, subclasses and packages

24 Importing Packages Java includes the import statement to bring certain classes or entire packages into visibility. Once imported, a class can be referred to directly, using only its name. The format is: import pkg1[.pkg2](classname)

25 Examples of Importing Packages import java.util.Date (import Date Package undre java, utility) import java.io.* (import IO packages under java)

26 Example (1)

27 Example (2) Create a file using import YourPackage.* (it will import any classes under this directory)

28 Your Class under YourPackage

29 More Example

30 More Example - Explanation Create a add class which has add and sub methods Create a lecture108 and import the add class Pass the value from agrs[0] and pass to add class to perform add and sub.

31 Summary Abstract classes – used as a family Using final with inheritance – the last method Packages – create class path Access protection – private, public protect (Packages) Importing packages – import other classes