Презентация 4. Java OOP. 4. Inheritance and Polymorphism онлайн
На нашем сайте вы можете скачать и просмотреть онлайн доклад-презентацию на тему 4. Java OOP. 4. Inheritance and Polymorphism абсолютно бесплатно. Урок-презентация на эту тему содержит всего 57 слайдов. Все материалы созданы в программе PowerPoint и имеют формат ppt или же pptx. Материалы и темы для презентаций взяты из открытых источников и загружены их авторами, за качество и достоверность информации в них администрация сайта не отвечает, все права принадлежат их создателям. Если вы нашли то, что искали, отблагодарите авторов - поделитесь ссылкой в социальных сетях, а наш сайт добавьте в закладки.
Презентации » Устройства и комплектующие » 4. Java OOP. 4. Inheritance and Polymorphism
Оцените!
Оцените презентацию от 1 до 5 баллов!
- Тип файла:ppt / pptx (powerpoint)
- Всего слайдов:57 слайдов
- Для класса:1,2,3,4,5,6,7,8,9,10,11
- Размер файла:309.50 kB
- Просмотров:55
- Скачиваний:0
- Автор:неизвестен
Слайды и текст к этой презентации:
№3 слайд
![Inheritance Basics of A class](/documents_6/80192aee437da50f7487cb2d9d087f7d/img2.jpg)
Содержание слайда: Inheritance Basics (2 of 3)
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).
Every class has one and only one direct superclass (single inheritance).
Class Object is exception, it is a root class
№5 слайд
![Members Inheritance A](/documents_6/80192aee437da50f7487cb2d9d087f7d/img4.jpg)
Содержание слайда: Members Inheritance
A subclass inherits all of the public and protected members of its parent, no matter what package the subclass is in.
If the subclass is in the same package as its parent, it also inherits the package-private members of the parent.
You can use the inherited members as is, replace them, hide them, or supplement them with new members
№16 слайд
![Methods Overriding and Hiding](/documents_6/80192aee437da50f7487cb2d9d087f7d/img15.jpg)
Содержание слайда: Methods Overriding and Hiding
You can write a new instance method in the subclass that has the same signature as the one in the superclass, thus overriding it.
You can write a new static method in the subclass that has the same signature as the one in the superclass, thus hiding it.
№20 слайд
![DepoBase Class of public](/documents_6/80192aee437da50f7487cb2d9d087f7d/img19.jpg)
Содержание слайда: DepoBase Class (1 of 2)
public class DepoBase {
protected Date startDate;
protected int dayLong;
protected double sum;
protected double interestRate;
public DepoBase() {}
public DepoBase(Date startDate, int dayLong, double sum,
double interestRate){
this.startDate = startDate;
this.dayLong = dayLong;
this.sum = sum;
this.interestRate = interestRate; }
№21 слайд
![DepoBase Class of accessors](/documents_6/80192aee437da50f7487cb2d9d087f7d/img20.jpg)
Содержание слайда: DepoBase Class (2 of 2)
// accessors
public double calculateInterest(LocalDate start, LocalDate maturity){
int startYear = start.getYear();
int maturityYear = maturity.getYear();
. . . . . . . . . .
double dayCf = start.until(maturity, ChronoUnit.DAYS)
+ 1;
double interest = sum * (interestRate / 100.0) *
(dayCf / daysInYear);
return interest;
}
№22 слайд
![DepoSimple Class public class](/documents_6/80192aee437da50f7487cb2d9d087f7d/img21.jpg)
Содержание слайда: DepoSimple Class
public class DepoSimple extends DepoBase{
public DepoSimple(){ }
public DepoSimple(Date startDate, int dayLong, double sum, double interestRate){
super(startDate, dayLong, sum, interestRate);
}
public double getInterest(){
double interest = 0.0;
. . . . . . . . . . . .
return interest;
}
№24 слайд
![Casting Objects of Casting](/documents_6/80192aee437da50f7487cb2d9d087f7d/img23.jpg)
Содержание слайда: Casting Objects (1 of 3)
Casting shows the use of an object of one type in place of another type, among the objects permitted by inheritance:
Object obj = new ClassName();
If, on the other hand, we write
ClassName cn = obj;
we would get a compile-time error because
obj is not known to the compiler to be a
ClassName
№25 слайд
![Casting Objects of We can](/documents_6/80192aee437da50f7487cb2d9d087f7d/img24.jpg)
Содержание слайда: Casting Objects (2 of 3)
We can tell the compiler to assign a ClassName to obj by explicit casting: ClassName cn = (ClassName)obj;
This cast inserts a runtime check that obj is assigned a ClassName so that the compiler can safely assume that obj is a ClassName
If obj is not a ClassName at runtime, a ClassCastException will be thrown.
№26 слайд
![Casting Objects of You can](/documents_6/80192aee437da50f7487cb2d9d087f7d/img25.jpg)
Содержание слайда: Casting Objects (3 of 3)
You can make a logical test as to the type of a particular object using the instanceof operator:
if (obj instanceof ClassName) {
ClassName myBike = (ClassName)obj;
}
The test x instanceof C does not generate an exception if x is null. It simply returns false.
№35 слайд
![Overriding Instance Methods I](/documents_6/80192aee437da50f7487cb2d9d087f7d/img34.jpg)
Содержание слайда: Overriding Instance Methods I
An instance method in a subclass with the same signature and return type as an instance method in the superclass overrides the superclass's method
The overriding method has the same name, number and type of parameters, and return type as the method it overrides.
An overriding method can also return a subtype of the type returned by the overridden method. This is called a covariant return type.
№36 слайд
![Overriding Instance Methods](/documents_6/80192aee437da50f7487cb2d9d087f7d/img35.jpg)
Содержание слайда: Overriding Instance Methods II
When overriding a method, you might want to use the @Override annotation that instructs the compiler that you intend to override a method in the superclass.
The access specifier for an overriding method can allow more, but not less, access than the overridden method (protected to public, but not to private)
№45 слайд
![Polymorphism of Connecting a](/documents_6/80192aee437da50f7487cb2d9d087f7d/img44.jpg)
Содержание слайда: Polymorphism (1 of 2)
Connecting a method call to a method body is called binding
When binding is performed before the program is run (e.g. by the compiler), it’s called early binding.
Late binding means that the binding occurs at run time, based on the type of object
There must be some mechanism to determine the type of the object at run time and to call the appropriate method
№46 слайд
![Polymorphism of All method](/documents_6/80192aee437da50f7487cb2d9d087f7d/img45.jpg)
Содержание слайда: Polymorphism (2 of 2)
All method binding in Java uses late binding unless the method is static or final (private methods are implicitly final)
You can write your code to talk to the base class and know that all the derived-class cases will work correctly using the same code
Typical example: create an array of Base class and fill it with subclasses objects. Then you can call the same method for each object from array elements
№48 слайд
![Exercise Interest Values Sum](/documents_6/80192aee437da50f7487cb2d9d087f7d/img47.jpg)
Содержание слайда: Exercise: Interest Values Sum
Date start = new GregorianCalendar(2013, Calendar.SEPTEMBER, 8).getTime();
DepoBase[] depo = new DepoBase[6];
depo[0] = new DepoSimple(start, 20, 1000.0, 15.0);
depo[1] = new DepoSimple(start, 20, 2500.0, 18.0);
depo[2] = new DepoBarrier(start, 40, 15000.0, 11.5);
depo[3] = new DepoBarrier(start, 80, 5000.0, 14.0);
depo[4] = new DepoMonthCapitalize(start, 180, 2000.0, 16.5);
depo[5] = new DepoMonthCapitalize(start, 91, 40000.0, 12.1);
№51 слайд
![Hiding Fields Within a class,](/documents_6/80192aee437da50f7487cb2d9d087f7d/img50.jpg)
Содержание слайда: Hiding Fields
Within a class, a field that has the same name as a field in the superclass hides the superclass's field, even if their types are different
Hided field in the superclass can be accessed through super keyword
Hiding fields is not recommended as it makes code difficult to read
№53 слайд
![Subclass Constructors of If a](/documents_6/80192aee437da50f7487cb2d9d087f7d/img52.jpg)
Содержание слайда: Subclass Constructors (2 of 2)
If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass
If the super class does not have a no-argument constructor, you will get a compile-time error
№55 слайд
![Writing Final Methods You use](/documents_6/80192aee437da50f7487cb2d9d087f7d/img54.jpg)
Содержание слайда: Writing Final Methods
You use the final keyword in a method declaration to indicate that the method cannot be overridden by subclasses
You might wish to make a method final if it has an implementation that should not be changed and it is critical to the consistent state of the object
Methods called from constructors should generally be declared final
If a constructor calls a non-final method, a subclass may redefine that method with surprising or undesirable results
Скачать все slide презентации 4. Java OOP. 4. Inheritance and Polymorphism одним архивом:
Похожие презентации
-
Java 4 WEB. Lesson 3 - OOP
-
Mathematical functions, characters, and strings. Introduction to Java Programming
-
Arrays and Loops
-
Internet and Java Foundations, Programming and Practice
-
OOP with C. Introduction C. Data Types. Variables, expressions, statements. C decision and iteration constructs
-
Arrays Loops. Java Core
-
Class and Object. Java Core
-
Nheritance, polymorphism, and virtual functions
-
Java Troubleshooting and Diagnostic
-
Java. SE. 06. Generic and collections