Object-Oriented Programming

Slides:



Advertisements
Similar presentations
Object Oriented Programming with Java
Advertisements

Chapter 1 Inheritance University Of Ha’il.
Data Structures Lecture 2 Fang Yu Department of Management Information Systems National Chengchi University Fall 2011.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Inheritance Inheritance Reserved word protected Reserved word super
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
Polymorphism. Legal assignments Widening is legal Narrowing is illegal (unless you cast) class Test { public static void main(String args[]) { double.
March 2004Object Oriented Design1 Object-Oriented Design.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object Concepts in C# Class, object, attribute, method, message, instance, encapsulation, polymorphism, inheritance, association, persistence, Generalization/specialization,
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Inheritance #1 First questions Similar to Python? What about visibility and encapsulation? – can an object of the child class access private members.
Like our natural language. Designed to facilitate the expression and communication ideas between people and computer Like our natural language. Designed.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Intro to OOP with Java, C. Thomas Wu
A class in Java is a software construct that includes fields (also called data fields or class scope variables) to provide data specification, and methods.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
2000 Jordan Anastasiade. All rights reserved. 1 Class In this lesson you will be learning about: Class. Inheritance. Polymorphism. Nested and.
Sun Certified Java Programmer, ©2004 Gary Lance, Chapter 5, page 1 Sun Certified Java 1.4 Programmer Chapter 5 Notes Gary Lance
Core Java: Essential Features 08/05/2015 Kien Tran.
Created by Terri Street Copyright, 2000  1,000,0001,000,000  500,000500,000  250,000250,000  125,000125,000  64,00064,000  32,00032,000  16,00016,000.
15440 Distributed Systems Recitation 1 Objected-Oriented Java Programming.
28-Dec-04polymorhism.ppt1 Polymorphism. 28-Dec-04polymorhism.ppt2 signatures in any programming language, a signature is what distinguishes one function.
Polymorphism. 3 main programming mechanisms that constitute OOP: 1. Encapsulation 2. Inheritance 3. Polymorphism.
Object-Oriented Design CSC 212. Announcements This course is speeding up and we are starting new material. Please see me if you feel this is going too.
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Inherited Classes in Java CSCI 392 Ch 6 in O’Reilly Adapted from Dannelly.
AD Lecture #1 Object Oriented Programming Three Main Principles 1 Inheritance Encapsulation Polymorphism.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
COME 339 WEEK 1. Example: The Course Class 2 TestCourceRunCourse.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Programming With Java ICS201 University Of Ha’il1 ICS 201 Introduction to Computer Science 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
OBJECT ORIENTED PROGRAMMING
OOP: Encapsulation &Abstraction
Lecture 12 Inheritance.
Objects as a programming concept
Inheritance and Polymorphism
Inheritance and Encapsulation
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
ATS Application Programming: Java Programming
Object Oriented Analysis and Design
OOP’S Concepts in C#.Net
CSC 205 Java Programming II
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Inherited Classes in Java
Inheritance.
Encapsulation Inheritance PolyMorhpism
Method Overriding in Java
Object-Oriented Programming
Polymorphism.
By Rajanikanth B OOP Concepts By Rajanikanth B
An Example of Inheritance
Eighth step for Learning C++ Programming
C++ Programming CLASS This pointer Static Class Friend Class
Chapter 11 Inheritance and Polymorphism Part 1
Final and Abstract Classes
Object Oriented Programming.
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
CS 240 – Advanced Programming Concepts
CSG2H3 Object Oriented Programming
Presentation transcript:

Object-Oriented Programming การโปรแกรมเชิงวัตถุด้วยภาษา JAVA Object-Oriented Programming มหาวิทยาลัยเนชั่น http://www.nation.ac.th บุรินทร์ รุจจนพันธุ์ . ปรับปรุง 24 สิงหาคม 2550

โปรแกรมภาษาจาวา class human { public static void main (String args[]) { System.out.println(“wow”); }

หลักพื้นฐานของ OO in Java 1. Inheritance 2. Encapsulation 3. Polymorphism 3.1 Overloading 3.2 Overriding

Inheritance class father { void homeaddr(){System.out.println(“lp”);} class child extends father { public static void main (String args[]) { homeaddr();

Encapsulation class friend { private int val; public int getter(){ return this.val;} public void setter(int a){ this.val=a;} } class child { public static void main (String args[]) { friend x = new friend(); x.setter(5); System.out.println(x.getter());

Polymorphism : Overloading overloaded methods: - appear in the same class or a subclass - have the same name but, - have different parameter lists, and, - can have different return type

Polymorphism : Overloading class child { static int bag(){ return 1; } static int bag(int a){ return a; } static int bag(String a){ return a.length(); } public static void main (String args[]) { System.out.println(bag()); System.out.println(bag(5)); System.out.println(bag(“abc”)); }

Polymorphism : Overriding overriding methods: - appear in subclasses have the same name as a superclass method - have the same parameter list as a superclass method - have the same return type as as a superclass method - the access modifier for the overriding method may not be more restrictive than the access modifier of the superclass method if the superclass method is public, the overriding method must be public if the superclass method is protected, the overriding method may be protected or public if the superclass method is package, the overriding method may be packagage, protected, or public if the superclass methods is private, it is not inherited and overriding is not an issue - the throws clause of the overriding method may only include exceptions that can be thrown by the superclass method, including it's subclasses

Polymorphism : Overriding (1/2) class father { static void addr(){System.out.println(“lp”);} } class child extends father { static void addr(){System.out.println(“cm”);} public static void main (String args[]) { addr(); new father().addr();

Polymorphism : Overriding (2/2) class father { void addr(){System.out.println(“lp”);} } class child extends father { void addr(){System.out.println(“cm”);} public static void main (String args[]) { child c = new child(); c.addr();