SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 40 | Next

Hasin Hayder

"Object-Oriented Programming with PHP5"

If you declare any variable in
subclass which is also available in superclass, then when you access that variable, the
one from subclass will be accessed.
Preventing from Overriding
If you declare any method as a final method, it can't be overridden in any of its
subclass. So if you don't want someone to override your class methods, declare it as
final. Let's take a look at the following example:
class SuperClass
{
public final function someMethod()
{
//..something here
}
}
class SubClass extends SuperClass
{
public function someMethod()
{
//..something here again, but it wont run
}
}
?>
If you execute the above code, it will generate a fatal error because class SubClass
tried to override a method in SuperClass which was declared as final.
Preventing from Extending
Similar to a final method, you can declare a class as final, which will prevent anyone
from extending it. So if you declare any class, as shown in following example, it is no
more extensible.
final class aclass
{
Chapter 2
[ 31 ]
}
class bclass extends aclass
{ }
?>
If you execute the code above, it will trigger the following error:
Fatal error: Class bclass may not inherit from final class
(aclass) in C:\OOP with PHP5\Codes\ch1\class.


Pages:
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6