You don't know #EP3
Why Java is not a pure object oriented programming language?

You don't know #EP3 Why Java is not a pure object oriented programming language?

Interviewers one of most fav question to ask.

It's really small concept not gonna take lot's of your time. Read it carefully.

What is pure object oriented programming language means? There are classes and objects in java but classes does not contain any memory. All memory holds inside the object. So what pure oop means everything should be inside object.

But java breaks two rules of pure object oriented

  1. Predefined primitive data types (int,float,char etc) These are not objects. They are primitive datatypes which breaks the rule of data should be stored inside object.

  2. You can access the members of a static class without creating an object of it. If you are familiar with static variables you will understand it easily. Those who are not Let me give you an example

Non-Static variables example

class Student{
     int id;
    String name;
    String college;
}

public class Demo {
    public static void main(String [] args) {
        Student std1= new Student();
        std1.id=49;
        std1.name="hrk";
        std1.college="RGCER";  //if you want to use instance(object) variables

    }
}

Static variables example

class Student{
     int id;
     String name;
     static String college="RGCER";
}

public class Demo {
    public static void main(String [] args) {
        Student std1= new Student();
        std1.id=49;
        std1.name="hrk";
        Student.college="YCCE"; //if you want to use class(static) variables

    }
}

Static variables are class variables not instance(object) variables. If you want to access those variables you will write class.variable_name

instance variables -> std1.college="RGCER";

Class variables -> Student.college="RGCER";

NOTE: The non-static variables which we use in example are called instance(object) variables and static variables are called class variables.

2nd Rule Break of Pure Object Oriented Language

Every data in oop should be access with instance(objects) but we can access the static variable with class name not with Object Hence It break the Second Rule.

Conclusion :

Reason 1 : Primitive Data type

Reason 2 : Data should be access with object but in java static variables are access with class name

Did you find this article valuable?

Support Hritik manbattulwar by becoming a sponsor. Any amount is appreciated!