אתחולים ובנאים יצירת מופע חדש של עצם כוללת : הקצאת זכרון, אתחול, הפעלת בנאים והשמה לשדות במסגרת ריצת הבנאי נקראים גם הבנאי / ים של מחלקת הבסיס תהליך זה.

Slides:



Advertisements
Similar presentations
Object Oriented Programming with Java
Advertisements

CE203 - Application Programming Autumn 2013CE203 Part 31 Part 3.
Web Application Development Slides Credit Umair Javed LUMS.
1 Inheritance Chapter 9. 2 Module Outcomes To develop a subclass from a superclass through inheritance To invoke the superclass ’ s constructors and methods.
Written by: Dr. JJ Shepherd
Inheritance Juan Marquez 12_inheritance.ppt
Intro to OOP with Java, C. Thomas Wu Inheritance and Polymorphism
Department of computer science N. Harika. Inheritance Inheritance is a fundamental Object Oriented concept A class can be defined as a "subclass" of another.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Inheritance and Polymorphism.
דוד שוורץ, עידן זק, נטע צור וחיה כהן. הפונקציונאליות : המשתמש יבחר קובץ שעליו הוא רוצה לבצע את האנליזה, וילחץ עליו עם כפתור ימני בעכבר. יפתח תפריט ובו.
1 Lecture 3 Inheritance. 2 A class that is inherited is called superclass The class that inherits is called subclass A subclass is a specialized version.
Inheritance. In this chapter, we will cover: The concept of inheritance Extending classes Overriding superclass methods Working with superclasses that.
CSE 115 Week 10 March , Announcements March 21 – Lab 7 Q & A in lecture March 21 – Lab 7 Q & A in lecture March 26 – Exam 7 March 26 – Exam.
JVM-1 Java Virtual Machine Reading Assignment: Chapter 1: All Chapter 3: Sections.
Java boot camp1 Subclasses Concepts: The subclass and inheritance: subclass B of class A inherits fields and methods from A. A is a superclass of B. Keyword.
CS 106 Introduction to Computer Science I 11 / 19 / 2007 Instructor: Michael Eckmann.
1 Inheritance and Polymorphism. 2 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common.
תכנות מונחה עצמים Object Oriented Programming (OOP) אתגר מחזור ב' Templates תבניות.
1 Further OO Concepts II – Java Program at run-time Overview l Steps in Executing a Java Program. l Loading l Linking l Initialization l Creation of Objects.
VB Classes ISYS 512. Adding a Class to a Project Project/Add Class –*** MyClass is a VB keyword. Steps: –Adding properties Declare Public variables in.
1 Introduction to Inheritance Overview l Inheritance ensures Reusability l Example of Inheritance l What is actually Inherited? l Overloading Vs. Overriding.
Vocabulary Key Terms polymorphism - Selecting a method among many methods that have the same name. subclass - A class that inherits variables and methods.
אתחול עצמים. אתחולים ובנאים יצירת מופע חדש של עצם כוללת: הקצאת זכרון, אתחול, הפעלת בנאים והשמה לשדות במסגרת ריצת הבנאי נקראים גם הבנאי/ם של מחלקת הבסיס.
Review of C++ Programming Part II Sheng-Fang Huang.
OOP Languages: Java vs C++
Unit 5 School of Information Systems & Technology1 School of Information Systems and Technology (IST)
CS/ENGRD 2110 FALL 2013 Lecture 5: Local vars; Inside-out rule; constructors 1.
Basic Object- Oriented Concepts Presented By: George Pefanis 21-Sep-15.
 2002 Prentice Hall. All rights reserved. 1 Introduction to Inheritance Inheritance: –1 of 3 main features of OOP –Form of software reusability –(Derived)
Sun Certified Java Programmer, ©2004 Gary Lance, Chapter 5, page 1 Sun Certified Java 1.4 Programmer Chapter 5 Notes Gary Lance
Inheritance and Polymorphism Daniel Liang, Introduction to Java Programming.
CS212: Object Oriented Analysis and Design Lecture 7: Arrays, Pointers and Dynamic Memory Allocation.
תוכנה 1 בשפת Java תרגול מספר 8: הורשה אסף זריצקי ומתי שמרת בית הספר למדעי המחשב אוניברסיטת תל אביב.
Inheritance CSC 171 FALL 2004 LECTURE 18. READING Read Horstmann, Chapter 11.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 4 – August 30, 2001.
Methods public class Demonstrate { public static void main (String argv[]) { public static void main (String argv[]) { int script = 6, acting = 9, directing.
MIT AITI 2004 – Lecture 12 Inheritance. What is Inheritance?  In the real world: We inherit traits from our mother and father. We also inherit traits.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Computer Science 111 Fundamentals of Computer Programming I Working with our own classes.
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Inheritance and Design CSIS 3701: Advanced Object Oriented Programming.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
Interfaces An interface is like an extreme case of an abstract class – However, an interface is not a class – It is a type that can be satisfied by any.
CPRG 215 Introduction to Object-Oriented Programming with Java Module 3- Introduction to Object Oriented Programming concepts Topic 3.4 Constructors, Overloading,
1 CS1110 Classes, stepwise refinement 17 Feb 2009 Miscellaneous points about classes. More on stepwise refinement. Next: wrapper classes. Section 5.1 of.
1 Object-Oriented Programming Inheritance. 2 Superclasses and Subclasses Superclasses and Subclasses  Superclasses and subclasses Object of one class.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 10 Inheritance and Polymorphism.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
CMSC 202 Polymorphism 2 nd Lecture. Aug 6, Topics Constructors and polymorphism The clone method Abstract methods Abstract classes.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
2-Oct-16 Basic Object-Oriented Concepts. 2 Concept: An object has behaviors In old style programming, you had: data, which was completely passive functions,
Written by: Dr. JJ Shepherd
Polymorphism 2nd Lecture
Chapter 11 Inheritance and Polymorphism
CS/ENGRD 2110 Spring 2014 Lecture 5: Local vars; Inside-out rule; constructors
CS100J Final Class on Classes 22 September 2005
Chapter 9 Inheritance and Polymorphism
Comp 249 Programming Methodology
Java Programming Language
CLASS DEFINITION (FIELDS)
Abstract methods and classes
مظفر بگ محمدی دانشگاه ایلام
Which best describes the relationship between classes and objects?
Inheritance.
Chapter 11 Inheritance and Polymorphism Part 1
CS100J Classes, stepwise refinement 21 September 2005
CS100J Final Class on Classes 10 February 2005
Presentation transcript:

אתחולים ובנאים יצירת מופע חדש של עצם כוללת : הקצאת זכרון, אתחול, הפעלת בנאים והשמה לשדות במסגרת ריצת הבנאי נקראים גם הבנאי / ים של מחלקת הבסיס תהליך זה מבלבל כי לשדה מסוים ניתן לבצע השמות גם ע " י אתחול, וגם ע " י מספר בנאים ( אחרון קובע ) בשקפים הבאים נתאר במדויק את התהליך נעזר בדוגמא

מה הסדר ביצירת מופע של מחלקה ? 1. שלב ראשון : הקצאת זיכרון לשדות העצם והצבת ערכי ברירת מחדל 2. שלב שני : נקרא הבנאי ( לפי חתימת new) והאלגוריתם הבא מופעל : 1.Bind constructor parameters. 2.If explicit this(), call recursively, and then skip to Step 5. 3.Call recursively the implicit or explicit super(...) [except for Object because Object has no parent class] 4.Execute the explicit instance variable initializers. 5.Execute the body of the current constructor.

דוגמא public class Employee extends Object { private String name; private double salary = ; private Date birthDate; public Employee(String n, Date DoB) { // implicit super(); name = n; birthDate = DoB; } public Employee(String n) { this(n, null); } public class Manager extends Employee { private String department; public Manager(String n, String d) { super(n); department = d; } public class Object { public Object() {} // … } {

הרצת הדוגמא מה קורה כאשר ה JVM מריץ את השורה Manager m = new Manager(“Joe Smith”, “Sales”); שלב ראשון : הקצאת זיכרון לשדות העצם והצבת ערכי ברירת מחדל (String) Name (double) Salary (Date) Birth Date (String) Department

תמונת הזכרון Basic initialization – Allocate memory for the complete Manager object – Initialize all instance variables to their default values Call constructor: Manager("Joe Smith", "Sales") – Bind constructor parameters: n="Joe Smith", d="Sales" – No explicit this() call – Call super(n) for Employee(String) Bind constructor parameters: n="Joe Smith" Call this(n, null) for Employee(String, Date) – Bind constructor parameters: n="Joe Smith", DoB=null – No explicit this() call – Call super() for Object() » No binding necessary » No this() call » No super() call (Object is the root) » No explicit variable initialization for Object » No method body to call – Initialize explicit Employee variables: salary= ; – Execute body: name="Joe Smith"; date=null; Steps skipped Execute body: No body in Employee(String) – No explicit initializers for Manager – Execute body: department="Sales" public class Manager extends Employee { private String department; public Manager(String n, String d) { super(n); department = d; } public class Employee extends Object { private String name; private double salary = ; private Date birthDate; public Employee(String n, Date DoB) { // implicit super(); name = n; birthDate = DoB; } public Employee(String n) { this(n, null); } 1. Bind parameters. 2. If explicit this(), goto super(), 4. explicit var. init. 5. Execute body (String) Name (double) Salary (Date) Birth Date (String) Department null 0.0 null “Joe Smith” “Sales”