Day 5 - Why is java not a Pure Object-Oriented language?
For any programming language to be called a pure object-oriented language, it should satisfy all the 7 rules below :
- Encapsulation/Data Hiding
- Inheritance
- Polymorphism
- Abstraction
- All predefined types are objects
- All user-defined types are objects
- All operations performed on objects must be only through methods exposed to the objects.
Java fails the rule no-5 and 7.
Why java fails the "All predefined types are objects" rule?
We have primitive data types - boolean, byte, char, int, float, double, long, short
which are predefined types but not objects.
Why java fails the "All operations performed on objects must be only through methods exposed at the objects" rule?
It's due to the static
keyword. When a variable is declared as static, they become class-level elements instead of instance variables. These static variables are accessible directly with the class name and can be used without the objects.