M a r c – o l i v e r p a h l Informatik I – Kapitel 8 Höhere objektorientierte Konzepte Zusammenfassung des Kapitel 8 Küchlin, Weber, Einführung in die.

Slides:



Advertisements
Similar presentations
Visualisierung der Funktionsweise des Programms auf S. 9 des Skripts
Advertisements

Introduction to classes Sangeetha Parthasarathy 06/11/2001.
Classes And Objects II. Recall the LightSwitch Class class LightSwitch { boolean on = true; boolean isOn() { return on; } void switch() { on = !on; }
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik virtuelle Maschine Verteilte.
Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java -
Informatik mit Java Grundkurs
1 Inheritance Classes and Subclasses Or Extending a Class.
1 Classes and Objects in Java Parameter Passing, Delegation, Visibility Control, and Object Cleanup.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
JSP and Servelets.
Session Tracking Problem: Identifizierung und Speicherung persönlicher Daten Warenkorb Lösung: Session mit ID Anmeldung ID REQ + ID RES ID: JKLMGHNB45kdse43k.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Interfaces (Part II) Course Lecture Slides 28 June 2010 A picture is.
Data Structures ADT List
The ArrayList Class and the enum Keyword
Object Oriented Programming with Java
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Chapter 8: Arrays.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Copyright © Recursive GCD Demo public class.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
Phil Campbell London South Bank University Java 1 First Steps.
Multi-Dispatch in the Java Virtual Machine TM What is (dynamic) multi-dispatch? Method selection based on the types of … all (or more than one) of the.
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
DATA STRUCTURES Lecture: Interfaces Slides adapted from Prof. Steven Roehrig.
Java Programming Abstract classes and Interfaces.
Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
Software Engineering Implementation Lecture 3 ASPI8-4 Anders P. Ravn, Feb 2004.
Interfaces CSC 171 FALL 2004 LECTURE 14. Project 1 review public class Rational { private int numerator, denominator; public Rational(int numerator, int.
Java Programming 2 Dr. Priti Srinivas Sajja Introductory concepts of java programming as specified in PGDCA 203:Object Technology, S P University.
Public class ABC { private int information = 0; private char moreInformation = ‘ ‘; public ABC ( int newInfo, char moreNewInfo) { } public ABC () {} public.
Objectives Understand grammar of OOP Understand equivalent Java code Discuss different implementations of classes and objects.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Using Classes to Store Data Computer Science 2 Gerb.
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.
FEN KbP: Seminar 2/JML-Intro1 JML Introduktion Specifikation af en Personklasse.
Paradigmer i Programmering 4 a. Java 1.5 -Generics -Autoboxing/unboxing -New for sætning -Static imports -enum.
1 More on Inheritance Overview l Object: The father of all classes l Casting and Classes l Object Cloning l Importance of Cloning.
1 Inheritance Overview l Inheritance ensures Reusability l Example of Inheritance l What is actually Inherited? l Overloading Vs. Overriding l Object:
Inheritance #1 First questions Similar to Python? What about visibility and encapsulation? – can an object of the child class access private members.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Introduction to Java Class Diagrams. Classes class Account { … } Account.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Introduction to Computation and Problem Solving Class 9: Static Methods and Data Members Prof. Steven R. Lerman and Dr. V. Judson Harward.
Inheritance (Part 4) Polymorphism and Abstract Classes 1.
Outline Creating Subclasses Overriding Methods Class Hierarchies Visibility Designing for Inheritance Inheritance and GUIs The Timer Class Copyright ©
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 17.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Inheritance in Java. Access Specifiers private keywordprivate keyword –Used for most instance variables –private variables and methods are accessible.
РНР. Уровень 4. Проектирование и разработка сложных веб-проектов на РНР 5 Reflection.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Lecture 12 Inheritance.
using System; namespace Demo01 { class Program
Architectural Patterns for Interactive Software
Web Design & Development Lecture 5
Class Inheritance (Cont.)
null, true, and false are also reserved.
Interface.
Everything the light touches, Simba, will be yours
Inheritance.
Object-Oriented Programming
Chapter 11: More on the Implications of Inheritance
Java Lesson 36 Mr. Kalmes.
Example with Static Variable
class PrintOnetoTen { public static void main(String args[]) {
Module 2 - Part 1 Variables, Assignment, and Data Types
Podcast Ch20b Title: TreeMap Design
Agenda Types and identifiers Practice Assignment Keywords in Java
Topics OOP Review Inheritance Review Abstract Classes
Presentation transcript:

m a r c – o l i v e r p a h l Informatik I – Kapitel 8 Höhere objektorientierte Konzepte Zusammenfassung des Kapitel 8 Küchlin, Weber, Einführung in die Informatik, 2.Auflage

2 m a r c – o l i v e r p a h l Vererbung Id private static int counter private int myId public Id() public int getId() Label private String name public String getName() public class Id { private static int counter = 1; private int myId; public Id(){ myId = counter++; } public int getId(){ return myId; } } public class Label extends Id { private String name; public Label() { // super(); // -> Id(); implizit! name = "unknown"; } public Label(String val) { name = val; } public String getName(){ return name; }

3 m a r c – o l i v e r p a h l Vererbung Id private static int counter private int myId public Id() public int getId() Label private String name public String getName() public class Main { public static void main(String[] args) { Label myLabel = new Label("as2004"); System.out.println( Das Gerät + myLabel.getName() + hat die Id+ myLabel.getId()); } Die Methoden der Klasse Id, von der geerbt wird, sind in Label auch automatisch vorhan- den!

4 m a r c – o l i v e r p a h l Vererbung/ Sichtbarkeit Id private static int counter private int myId public Id() public int getId() Label private String name public String getName() public class Id {... private int myId;... } public class Label extends Id {... public Label(String val) { name = val; super.myId = 0; //hier: myId = 0; }... } geht NICHT, da das Feld private ist!

5 m a r c – o l i v e r p a h l Vererbung/ Sichtbarkeit Id private static int counter protected int myId public Id() public int getId() Label private String name public String getName() public class Id {... private int myId;... } public class Label extends Id {... public Label(String val) { super(); name = val; super.myId = 0; //hier: myId = 0; }... } geht, da das Feld protected ist!

6 m a r c – o l i v e r p a h l Vererbung/ Sichtbarkeit Id private static int counter protected int myId public Id() public int getId() Label private String name private int myId public String getName() public class Id {... private int myId;... } public class Label extends Id {... public Label(String val) { super(); name = val; super.myId = 0; // NICHT = myId = 0; myId = 23; }... }

7 m a r c – o l i v e r p a h l virtuelle Funktionen/ Überschreiben public class Parent { public void method(){ System.out.println("Methode des Parent."); } public class Child extends Parent { public void method(){ System.out.println("Methode des Child."); } public class Main { public static void main(String[] args) { Parent eins = new Parent(); Parent zwei = new Child(); eins.method(); zwei.method(); }

8 m a r c – o l i v e r p a h l virtuelle Funktionen/ Überschreiben/ final public class Parent { public final void method(){ System.out.println("Methode des Parent."); } public class Child extends Parent { public void method(){ System.out.println("Methode des Child."); } public class Main { public static void main(String[] args) { Parent eins = new Parent(); Parent zwei = new Child(); eins.method(); zwei.method(); }

9 m a r c – o l i v e r p a h l ADT/ Interfaces/ Selektoren Kundenklasse Schnittstelle/ Interface interne Repräsentation/ Implementierung public class Main { public static void main(String[] args){ ZahlenSpeicher z1 = new ZahlenSpeicher1(); ZahlenSpeicher z2 = new ZahlenSpeicher2(); z1.setValue(7); z2.setValue(8); System.out.println("z1+z2= " +(z1.getValue()+z2.getValue())); } public interface ZahlenSpeicher { public int getValue(); public void setValue(int val);} public class ZahlenSpeicher1 implements ZahlenSpeicher { private int theValue = 0; public int getValue(){ return theValue; } public void setValue(int val){ theValue = val; } } public class ZahlenSpeicher2 implements ZahlenSpeicher { private String theValue; public int getValue(){ return Integer.parseInt(theValue); } public void setValue(int val){ theValue = Integer.toString(val); } }

10 m a r c – o l i v e r p a h l generisches Programmieren Stichwort: Muster –in C++ –in Java template class Node{ private: T data; Node* next; public: T getData();... } public static void inc(ZahlenSpeicher z){ z.setValue(z.getValue()+1); } Funktioniert generisch für alle beliebigen Implementierungen des Interface ZahlenSpeicher