Object orientation and Packaging in Java. 2 4.0 Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Chapter 1 Inheritance University Of Ha’il.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
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.
Inheritance Inheritance Reserved word protected Reserved word super
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
ACM/JETT Workshop - August 4-5, :Inheritance and Interfaces.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics (inheritance review + Java generics)
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
CPSC150 Abstract Classes and Interfaces Chapter 10.
Chapter 10 Classes Continued
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2007.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Object-Oriented Programming Concepts
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Object Oriented Programming
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Java Software Solutions Lewis and Loftus Chapter 9 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Enhanced Class Design -- Introduction.
Introduction to Object-Oriented Programming Lesson 2.
JAVA Programming (Session 4) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Classes, Interfaces and Packages
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
BY:- TOPS Technologies
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Modern Programming Tools And Techniques-I
Sections Inheritance and Abstract Classes
Objects as a programming concept
Inheritance and Polymorphism
Types of Programming Languages
Object Oriented Analysis and Design
OOP’S Concepts in C#.Net
Interface.
Java Programming Language
Advanced Java Topics Chapter 9
Interfaces.
METHOD OVERRIDING in JAVA
Inheritance Cse 3rd year.
Java Inheritance.
Chapter 9 Carrano Chapter 10 Small Java
Inheritance and Polymorphism
Final and Abstract Classes
Presentation transcript:

Object orientation and Packaging in Java

2 4.0 Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify objects and make you think in a object oriented way. Objective: After completing this chapter you will able to, create objects Implement Inheritance Create abstract Class Create Interfaces Implement overriding and overloading

3 Introduction to Objects Software bundles of data –Methods: Procedures act on that data. –Objects: The merger of data and methods Objects have two characteristics: –State –Behavior State: –Determined by its data Behavior: –Defined by its methods

4 Introduction to Objects Sample Java Bean: public class Animal { private String name; public String getName(){ return name; } public void setName(String name) { this.name = name; }

5 Inheritance Process of creating a new class with the characteristics of an existing class, along with additional characteristics unique to the new class Features: –Provides a powerful and natural mechanism for organizing and structuring programs –Provides a means to create classes based on other classes –When a class is based on another class, it inherits all the properties of that class, including the data and methods for the class –The class doing the inheriting is referred to as the subclass (child class), and the class providing the information to inherit is referred to as the superclass (parent class)‏ –subclasses can add variables and methods to the ones they inherited from the superclass

6 Abstract Class Abstract Class: –Super classes that act purely as templates for more usable subclasses –Serves as nothing more than an abstraction for the common class functionality shared by the subclasses –Cannot be instantiated Reason: - Parts of it have been specifically left unimplemented - More specifically, these parts are made up of methods that have yet to be implemented—abstract methods

7 Interfaces Is a prototype for a class Useful from a logical design perspective Are abstract classes that are left completely unimplemented Interface member data is limited to static final variables, which means that they are constant A class can implement multiple interfaces If a class implements multiple interfaces, that class must provide all of the functionality for the methods defined in the interfaces

8 Interfaces Benefits: –Provide a means to define the protocols for a class without worrying with the implementation details –Once interfaces have been designed, the class development can take place without worrying about communication among classes Syntax: –The syntax for creating interfaces follows: interface Identifier { InterfaceBody } Identifier is the name of the interface InterfaceBody refers to the abstract methods and static final variables that make up the interface It isn’t necessary to use the abstract keyword for the methods

9 Interfaces Implementing Interfaces: To implement an interface, you use the implements keyword class Identifier implements Interface { ClassBody } –Identifier refers to the name of the new class –Interface is the name of the interface you are implementing, and ClassBody is the new class body –The class must implement all the methods declared in the interface or must be itself an interface extending the first interface

10 Overriding A subclass can give a different implementation for a method already defined in the super class. Rules: –The signature of the method in the subclass must exactly be the same as that of the super class –The access modifier of the overriding method of the subclass cannot be more narrow than that allowed by super class –The overriding method of the subclass cannot throw a broader exception than that thrown by the super class unless it’s a runtime exception –Method overriding is a simple, yet powerful usage of object-oriented design

11 Overloading Enables you to specify different types of information (parameters) to send to a method Rules: –To overload a method, you declare another version with the same name but different parameters –You cannot differentiate two overloaded methods by their return types alone –The access modifiers and the exceptions thrown can be of any type for these two overloaded methods The compiler keeps up with the parameters for each method along with the name When a call to a method is encountered in a program, the compiler checks the name and the parameters to determine which overloaded method is being called

12 Object Orientation and Packaging: Summary Software bundles of data –Methods: Procedures act on that data. –Objects: The merger of data and methods Inheritance - Process of creating a new class with the characteristics of an existing class, along with additional characteristics unique to the new class Abstract Class - Super classes that act purely as templates for more usable subclasses Interface - Is a prototype for a class Overriding - A subclass can give a different implementation for a method already defined in the super class. Overloading - Enables you to specify different types of information (parameters) to send to a method

13 Test Your Understanding What is Inheritence? Where can it be used? How do you decide as to whether to use an interface or an abstract class? What is overriding and overloading?