Pages

Showing posts with label OOPS. Show all posts
Showing posts with label OOPS. Show all posts

Sunday, September 15, 2013

OOPS-What is the difference between Static and Final Keyword

Static
A static method remains common for all objects and can be called directly without the need of creation of any object.

For Example : classname::functionname();

A static property on the other end remains common for all the objects.It preserves its last changed state by any object.

Final
Final keyword on other end does not allows a class to be extended a method to be overridden in subclass or to change a property respective to its use in a class.

Saturday, September 14, 2013

OOPS-PHP4,PHP5-difference

1. In PHP4 there are no access modifiers everything is open we can't use public,private or protected for our methods.

2. In PHP4 there are interfaces but no abstract or final keyword.

An interface can be implemented by any object and which means that all the functions of interface must be implemented by the object.We can only declare the name and access type of any method in an interface.

An abstract class is where some methods may have some body too.

A final class cannot be extended.

3. In PHP4 there is no multiple inheritances for interfaces but Php5 supports multiple inheritance via implementing multiple interfaces together.

4. In PHP4 everything is static i.e if we declare any method in class which uses $this keyword we can call the same via classname::method() i.e. without instantiating the class which is not allowed in PHP5.

5. There is no class based constant,static property,destructor in PHP 4.

6. PHP 4 allows shallow copy of object.But in PHP 5 shallow copy is possible only via clone keyword.

7. PHP 4 does not have an exception object where as PHP 5 has an exception object.

8. Method over loading via magic functions like __get() and __set() is possible in PHP 5

Tuesday, September 27, 2011

Boxing and Unboxing in OOPS

Boxing is a process of conversion of a value to generic object type for example

Consider the following code

Int alpha=1;
object boxed_alpha= alpha;

This conversion to generic type is called as boxing

Unboxing is the reverse of a boxing continuing with the above example let us unbox boxed_alpha as a string

String string_alpha=(String) boxed_alpha;

OR

String string_alpha=boxed_alpha.ToString();

I will discuss its use subsequent comments