Java - Common Myths about OOPs Concepts

1. Constructor creates the objects.

Fact - New operator in Java creates objects. Constructor is the later step in object creation. Constructor's job is to initialize the members after the object has reserved memory for itself.

2. Final Variables should be defined during declaration.

Fact - Final variables should be defined before or during object creation. Final variables can also be defined within constructor.

3. Static methods cannot access instance variables.

Fact - Though Static methods cannot access the instance variables directly, They can access them using instance handler.   

4. Declaring an object "final" makes it immutable.

Fact - Only declaring primitive types as final makes them immutable. Making objects final means that the object handler cannot be used to target some other object but the object is still mutable.

5. We can make an object "Singleton".

Fact - There are no singleton objects. Only Classes can be made Singleton to have one object only.

6. Java Supports multiple inheritance as class can implement multiple interfaces.

Fact - With Java 8 , This has become debatable now. Interface implementation facilitate partial inheritance ( i.e only default methods wef from Java8 ). Java doesn't support multiple class inheritance. Though an Interface can extend multiple Interfaces.

7. equals and == means the same thing.

Fact - "equals" is the member of object class which returns true if the content of objects are same whereas "==" evaluate to see if the object handlers on the left and right are pointing to the same object in memory.

8. "instanceOf" method is used to check if specified object is an instance of Specified Class

Fact -  "instanceOf" method returns true if the object is either an instance of mentioned Class or any of the subclass of the mentioned Class. instanceOf can be used with Interfaces too so as to check if the respective class implements the interface.

9. Default constructor is provided by the compiler if we don't declare any non parameterized constructor.

Fact - Default constructor is provided by the compiler if we don't declare any constructor. If we declare a parameterized constructor, Compiler will not create any default non parameterized constructor for the class.