Compare classes with C++
Some significant points to consider when defining a class in java as you probably noticed from above given skeleton are
- There are no global functions or variables . Everything resides inside a class. Remember that we wrote our main method inside a class. (For instance , in HelloWorldApp program)
- Specify access modifiers (public, private or protected) for every member method or data members at each line.
- public: accessible anywhere by anyone
- private: Only accessible within this class
- protect: accessible only to the class itself and to it's subclasses or other classes in same package.
- default: default access if no access modifier is provided. Accessible to all classes in same package.
- There is no semicolon (;) at the end of class.
- All methods (functions) are written inline. There are no separate header and implementation files.
- Automatic initialization of class level data members if you don't initialize them Primitives
o Numeric (int, float etc) with zero
o Char with null
o Boolean with false
Object References
- With null