🗊Презентация Object oriented programming. (Lesson 6, part 2)

Нажмите для полного просмотра!
Object oriented programming. (Lesson 6, part 2), слайд №1Object oriented programming. (Lesson 6, part 2), слайд №2Object oriented programming. (Lesson 6, part 2), слайд №3Object oriented programming. (Lesson 6, part 2), слайд №4Object oriented programming. (Lesson 6, part 2), слайд №5Object oriented programming. (Lesson 6, part 2), слайд №6Object oriented programming. (Lesson 6, part 2), слайд №7Object oriented programming. (Lesson 6, part 2), слайд №8Object oriented programming. (Lesson 6, part 2), слайд №9Object oriented programming. (Lesson 6, part 2), слайд №10Object oriented programming. (Lesson 6, part 2), слайд №11Object oriented programming. (Lesson 6, part 2), слайд №12Object oriented programming. (Lesson 6, part 2), слайд №13Object oriented programming. (Lesson 6, part 2), слайд №14Object oriented programming. (Lesson 6, part 2), слайд №15Object oriented programming. (Lesson 6, part 2), слайд №16Object oriented programming. (Lesson 6, part 2), слайд №17Object oriented programming. (Lesson 6, part 2), слайд №18Object oriented programming. (Lesson 6, part 2), слайд №19Object oriented programming. (Lesson 6, part 2), слайд №20Object oriented programming. (Lesson 6, part 2), слайд №21Object oriented programming. (Lesson 6, part 2), слайд №22Object oriented programming. (Lesson 6, part 2), слайд №23Object oriented programming. (Lesson 6, part 2), слайд №24Object oriented programming. (Lesson 6, part 2), слайд №25Object oriented programming. (Lesson 6, part 2), слайд №26Object oriented programming. (Lesson 6, part 2), слайд №27Object oriented programming. (Lesson 6, part 2), слайд №28Object oriented programming. (Lesson 6, part 2), слайд №29Object oriented programming. (Lesson 6, part 2), слайд №30Object oriented programming. (Lesson 6, part 2), слайд №31Object oriented programming. (Lesson 6, part 2), слайд №32Object oriented programming. (Lesson 6, part 2), слайд №33Object oriented programming. (Lesson 6, part 2), слайд №34

Вы можете ознакомиться и скачать презентацию на тему Object oriented programming. (Lesson 6, part 2). Доклад-сообщение содержит 34 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1





Object Oriented Programming
 (part 2)
Описание слайда:
Object Oriented Programming (part 2)

Слайд 2





Agenda
Inheritance
Fields/Methods in Extended Classes
Constructors in extended classes
Inherited object construction
Overloading and Overriding Methods
Polymorphism
Type compatibility
Описание слайда:
Agenda Inheritance Fields/Methods in Extended Classes Constructors in extended classes Inherited object construction Overloading and Overriding Methods Polymorphism Type compatibility

Слайд 3





Agenda
Type conversion
protected members
Object: the ultimate superclass
Описание слайда:
Agenda Type conversion protected members Object: the ultimate superclass

Слайд 4





Inheritance
Inheritance: you can create new classes that are built on existing classes. Through the way of inheritance, you can reuse the existing class’s methods and fields, and you can also add new methods and fields to adapt the new classes to new situations
Subclass and superclass have a IsA relationship: an object of a subclass IsA(n) object of its superclass
Описание слайда:
Inheritance Inheritance: you can create new classes that are built on existing classes. Through the way of inheritance, you can reuse the existing class’s methods and fields, and you can also add new methods and fields to adapt the new classes to new situations Subclass and superclass have a IsA relationship: an object of a subclass IsA(n) object of its superclass

Слайд 5





Inheritance
"is a" relationship
Inheritance
"has a" relationship
Composition, having other objects as members
Example
	 Employee “is a” BirthDate;    //Wrong!
	 Employee “has a” Birthdate;  //Composition
Описание слайда:
Inheritance "is a" relationship Inheritance "has a" relationship Composition, having other objects as members Example Employee “is a” BirthDate; //Wrong! Employee “has a” Birthdate; //Composition

Слайд 6





Definitions
A class that is derived from another class is called a subclass (also a derived class, extended class, or child class). 
The class from which the subclass is derived is called a superclass (also a base class or a parent class).
Описание слайда:
Definitions A class that is derived from another class is called a subclass (also a derived class, extended class, or child class). The class from which the subclass is derived is called a superclass (also a base class or a parent class).

Слайд 7





Definitions
Excepting Object, which has no superclass, every class has one and only one direct superclass (single inheritance).
Описание слайда:
Definitions Excepting Object, which has no superclass, every class has one and only one direct superclass (single inheritance).

Слайд 8





Definitions
Every class is an extended (inherited) class, whether or not it’s declared to be. If a class does not declared to explicitly extend any other class, then it implicitly extends the Object class
Описание слайда:
Definitions Every class is an extended (inherited) class, whether or not it’s declared to be. If a class does not declared to explicitly extend any other class, then it implicitly extends the Object class

Слайд 9





Inheritance
modifier(s) class ClassName extends ExistingClassName {}
Описание слайда:
Inheritance modifier(s) class ClassName extends ExistingClassName {}

Слайд 10





sample classes
Superclass

public class Person{
	private String name;
	public Person ( ) {
		name = “no_name_yet”;
	}
	public Person ( String initialName ) {
		this.name = initialName;
	}
	public String getName ( ) {
		return name;
	}
	public void setName ( String newName ) {
		name = newName;
	}
Описание слайда:
sample classes Superclass public class Person{ private String name; public Person ( ) { name = “no_name_yet”; } public Person ( String initialName ) { this.name = initialName; } public String getName ( ) { return name; } public void setName ( String newName ) { name = newName; }

Слайд 11





Inheritance
Class hierarchy of previous example
				Object
				
				Person
				Student
Описание слайда:
Inheritance Class hierarchy of previous example Object Person Student

Слайд 12





Fields/Methods in Extended Classes
An object of an extended class contains two sets of variables and methods
fields/methods which are defined locally in the extended class
fields/methods which are inherited from the superclass
What are the fields for a Student object in the previous example ?
Описание слайда:
Fields/Methods in Extended Classes An object of an extended class contains two sets of variables and methods fields/methods which are defined locally in the extended class fields/methods which are inherited from the superclass What are the fields for a Student object in the previous example ?

Слайд 13





Constructors in extended classes
A constructor of the extended class can invoke one of the superclass’s constructors by using the super method.
If no superclass constructor is invoked explicitly, then the superclass’s no-arg constructor 
			 super( ) 
	is invoked automatically as the first statement of the extended class’s constructor. 
Constructors are not methods and are NOT inherited.
Описание слайда:
Constructors in extended classes A constructor of the extended class can invoke one of the superclass’s constructors by using the super method. If no superclass constructor is invoked explicitly, then the superclass’s no-arg constructor super( ) is invoked automatically as the first statement of the extended class’s constructor. Constructors are not methods and are NOT inherited.

Слайд 14





Three phases of an object’s construction
When an object is created, memory is allocated for all its fields, which are initially set to be their default values. It is then followed by a three-phase construction:
 invoke a superclass’s constructor
 initialize the fields by using their initializers and initialization blocks
 execute the body of the constructor
The invoked superclass’s constructor is executed using the same three-phase constructor. This process is executed recursively until the Object class is reached
Описание слайда:
Three phases of an object’s construction When an object is created, memory is allocated for all its fields, which are initially set to be their default values. It is then followed by a three-phase construction: invoke a superclass’s constructor initialize the fields by using their initializers and initialization blocks execute the body of the constructor The invoked superclass’s constructor is executed using the same three-phase constructor. This process is executed recursively until the Object class is reached

Слайд 15





To Illustrate the Construction Order. . .
Описание слайда:
To Illustrate the Construction Order. . .

Слайд 16





Overloading and Overriding Methods
Overloading: providing more than one method with the same name but different parameter list
 overloading an inherited method means simply adding new method with the same name and different signature
Overriding: replacing the superclass’s implementation of a method with your own design. 
both the parameter lists and the return types must be exactly the same
if an overriding method is invoked on an object of the subclass, then it’s the subclass’s version of this method that gets implemented 
an overriding method can have different access specifier from its superclass’s version, but only wider accessibility is allowed
the overriding method’s throws clause can have fewer types listed than the method in the superclass, or more specific types
Описание слайда:
Overloading and Overriding Methods Overloading: providing more than one method with the same name but different parameter list overloading an inherited method means simply adding new method with the same name and different signature Overriding: replacing the superclass’s implementation of a method with your own design. both the parameter lists and the return types must be exactly the same if an overriding method is invoked on an object of the subclass, then it’s the subclass’s version of this method that gets implemented an overriding method can have different access specifier from its superclass’s version, but only wider accessibility is allowed the overriding method’s throws clause can have fewer types listed than the method in the superclass, or more specific types

Слайд 17





Accessibility and Overriding
a method can be overridden only if it’s accessible in the subclass
private methods in the superclass
cannot be overridden
if a subclass contains a method which has the same signature as one in its superclass, these methods are totally unrelated
package methods in the superclass
can be overridden if the subclass is in the same package as the superclass
protected, public methods
always will be 
       Not as that simple as it seems!
Описание слайда:
Accessibility and Overriding a method can be overridden only if it’s accessible in the subclass private methods in the superclass cannot be overridden if a subclass contains a method which has the same signature as one in its superclass, these methods are totally unrelated package methods in the superclass can be overridden if the subclass is in the same package as the superclass protected, public methods always will be Not as that simple as it seems!

Слайд 18


Object oriented programming. (Lesson 6, part 2), слайд №18
Описание слайда:

Слайд 19


Object oriented programming. (Lesson 6, part 2), слайд №19
Описание слайда:

Слайд 20





Hiding fields
Fields cannot be overridden, they can only be hidden
If a field is declared in the subclass and it has the same name as one in the superclass, then the field belongs to the superclass cannot be accessed directly by its name any more
Описание слайда:
Hiding fields Fields cannot be overridden, they can only be hidden If a field is declared in the subclass and it has the same name as one in the superclass, then the field belongs to the superclass cannot be accessed directly by its name any more

Слайд 21





Polymorphism
Java allows us to treat an object of a subclass as an object of its superclass. In other words, a reference variable of a superclass type can point to an object of its subclass. 
 when you invoke a method through an object reference, the actual class of the object decides which implementation is used
 when you access a field, the declared type of the reference decides which implementation is used
Описание слайда:
Polymorphism Java allows us to treat an object of a subclass as an object of its superclass. In other words, a reference variable of a superclass type can point to an object of its subclass. when you invoke a method through an object reference, the actual class of the object decides which implementation is used when you access a field, the declared type of the reference decides which implementation is used

Слайд 22





Polymorphism
Late binding or dynamic binding (run-time binding): 
Method to be executed is determined at execution time, not compile time.
The term polymorphism means to assign multiple meanings to the same method name. 
In Java, polymorphism is implemented using late binding.
These reference variables have many forms, that is, they are polymorphic reference variables. They can refer to objects of their own class or to objects of the classes inherited from their class.
Описание слайда:
Polymorphism Late binding or dynamic binding (run-time binding): Method to be executed is determined at execution time, not compile time. The term polymorphism means to assign multiple meanings to the same method name. In Java, polymorphism is implemented using late binding. These reference variables have many forms, that is, they are polymorphic reference variables. They can refer to objects of their own class or to objects of the classes inherited from their class.

Слайд 23


Object oriented programming. (Lesson 6, part 2), слайд №23
Описание слайда:

Слайд 24





Type compatibility
Java is a strongly typed language. 
Compatibility
when you assign the value of an expression to a variable, the type of the expression must be compatible with the declared type of the variable: it must be the same type as, or a subtype of, the declared type
 null object reference is compatible with all reference types.
Описание слайда:
Type compatibility Java is a strongly typed language. Compatibility when you assign the value of an expression to a variable, the type of the expression must be compatible with the declared type of the variable: it must be the same type as, or a subtype of, the declared type null object reference is compatible with all reference types.

Слайд 25





Type conversion (1)
The types higher up the type hierarchy are said to be wider, or less specific than the types lower down the hierarchy. Similarly, lower types are said to be narrower, or more specific.
Widening conversion: assign a subtype to a supertype
 can be checked at compile time. No action needed
Narrowing conversion: convert a reference of a supertype into a reference of a subtype
 must be explicitly converted by using the cast operator
Описание слайда:
Type conversion (1) The types higher up the type hierarchy are said to be wider, or less specific than the types lower down the hierarchy. Similarly, lower types are said to be narrower, or more specific. Widening conversion: assign a subtype to a supertype can be checked at compile time. No action needed Narrowing conversion: convert a reference of a supertype into a reference of a subtype must be explicitly converted by using the cast operator

Слайд 26





Type conversion (2)
Описание слайда:
Type conversion (2)

Слайд 27





Type conversion (3)
Type testing: you can test an object’s actual class by using the instanceof operactor
	e.g.	if ( obj instanceof String)
		{
		   String str2 = (String)obj;	
		}
Описание слайда:
Type conversion (3) Type testing: you can test an object’s actual class by using the instanceof operactor e.g. if ( obj instanceof String) { String str2 = (String)obj; }

Слайд 28





protected members
To allow subclass methods to access a superclass field, define it protected. But be cautious!
Making methods protected makes more sense, if the subclasses can be trusted to use the method correctly, but other classes cannot.
Описание слайда:
protected members To allow subclass methods to access a superclass field, define it protected. But be cautious! Making methods protected makes more sense, if the subclasses can be trusted to use the method correctly, but other classes cannot.

Слайд 29





What protected really means
Описание слайда:
What protected really means

Слайд 30





Protected Example
Описание слайда:
Protected Example

Слайд 31





Object: the ultimate superclass
The object class is the ultimate ancestor: every class in Java extends Object without mention
Utility methods of Object class
 equals: returns whether two object references have the same value
 hashCode: return a hash code for the object, which is derived from the object’s memory address. Equal objects should return identical hash codes
 clone: returns a clone of the object
 getClass: return the run expression of the object’s class, which is a Class object
 finalize: finalize the object during garbage collection
 toString: return a string representation of the object
Описание слайда:
Object: the ultimate superclass The object class is the ultimate ancestor: every class in Java extends Object without mention Utility methods of Object class equals: returns whether two object references have the same value hashCode: return a hash code for the object, which is derived from the object’s memory address. Equal objects should return identical hash codes clone: returns a clone of the object getClass: return the run expression of the object’s class, which is a Class object finalize: finalize the object during garbage collection toString: return a string representation of the object

Слайд 32





The class Object:
 Equivalent Definition of a Class
public class Clock
{
   //Declare instance variables as given in Chapter 8
   //Definition of instance methods as given in Chapter 8       
   //...
}
public class Clock extends Object
{
  //Declare instance variables as given in Chapter 8      //Definition of instance methods as given in Chapter 8
  //...
}
Описание слайда:
The class Object: Equivalent Definition of a Class public class Clock { //Declare instance variables as given in Chapter 8 //Definition of instance methods as given in Chapter 8 //... } public class Clock extends Object { //Declare instance variables as given in Chapter 8 //Definition of instance methods as given in Chapter 8 //... }

Слайд 33





final Methods and Classes
Declaring variables final
Indicates they cannot be modified after declaration
Must be initialized when declared
Declaring methods final
Cannot be overridden in a subclass
static and private methods are implicitly final
Program can inline final methods
Actually inserts method code at method call locations
Improves program performance
Declaring classes final
Cannot be a superclass (cannot inherit from it)
All methods in class are implicitly final
Описание слайда:
final Methods and Classes Declaring variables final Indicates they cannot be modified after declaration Must be initialized when declared Declaring methods final Cannot be overridden in a subclass static and private methods are implicitly final Program can inline final methods Actually inserts method code at method call locations Improves program performance Declaring classes final Cannot be a superclass (cannot inherit from it) All methods in class are implicitly final

Слайд 34






This and super keywords
Описание слайда:
This and super keywords



Похожие презентации
Mypresentation.ru
Загрузить презентацию