CP1344: PROGRAMMING IN JAVA - LECTURE -40- FINALIZER METHODS- BCA- S3.
Автор: BOSCOCAMPUSVISION
Загружено: 2020-08-19
Просмотров: 107
Описание:
Finalizer Methods
We have seen that a constructor method is used to initialize an object when it is declared. This process is known as initialization, Similarly, Java supports a concept called finalization, which is just opposite to initialization. We know that Java run-time is an automatic garbage collecting system. It automatically frees up the memory resources used by the objects. But objects may hold other non-object resources such as file descriptors or window system fonts. The garbage collector cannot free these resources. In order to free these resources we must use a finalizer method. This is similar to destructors in C++.
The finalizer method is simply finalize( ) and can be added to any class. Java calls that method whenever it is about to reclaim the space for that object. The finalize method should explicitly define the tasks to be performed.
Abstract Methods and Classes
We have seen that by making a method final we ensure that the method is not redefined in a subclass. That is, the method can never be subclassed. Java allows us to do something that is exactly opposite to this. That is, we can indicate that a method must always be redefined in a subclass, thus making overriding compulsory. This is done using the modifier keyword abstract in the method definition.
Example:
abstract class Shape
{
abstract void draw( );
}
When a class contains one or more abstract methods, it should also be declared abstract as shown in the example above.
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: