Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!

Naresh Joshi

Greenhorn
+ Follow
since Feb 13, 2013
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Naresh Joshi

We should define members as static which

1. Should be common to all objects of the class.
2. Should belong to the class and accessible by class name.
3. Should not need an object of class to access them.

Now suppose we are defining an outer class as static and suppose we are allowed to do so. Will this serve any purpose or provide any advantage to a developer or it will create ambiguity and complications for both developers and language creators?

Let’s check, defining an outer class as static will serve purposes which we have defined above or not?

1. Every class is already common to all of its objects and there is no need to make it static to become available to all of its objects.
2. We need a class name to access its static members because these members are part of class while an outer class is part of package and we can directly access the class by just writing package_name.class_name (similar to class_name.static_field_name), So again there is no need to do which is already there by default.
3. We do not need any object to access a class if it is visible, we can simply write package_name.class_name to access it. And by definition, a class is a blueprint for its objects and we create a class to create objects from it (exception will always be there e.g. java.lang.Math), again there is no need to define an outer class as static.

From above points, we can say Java creators had not allowed an outer class to be static because there is no need to make it static. Allowing to make the outer class static will only increase complications, ambiguity and duplicity. Read more on Why An Outer Java Class Can’t Be Static
4 years ago

Ishan Pandya wrote:These static fields belong to an OBJECT. this object is a Class Level object.
Each class has it own "Class" object which can be obtained by ClassName.class
The static members belong to this object.
This is my understanding. Not pretty sure about it but still.

do have a look at this Java.lang .Class

thanks


thanks buddy, it is little bit satisfying.
8 years ago
Hey friends i am trying to design a reader program which can read all type of document (e.g. .doc, .text, .pdf, etc) for my android phone,
please tell me where from i should start ?
8 years ago

Campbell Ritchie wrote:Welcome to the Ranch If you search this forum for “pure object oriented”, you find many people have asked the same question before.
You would have to read the JVM specification to find whether the location of static members is specified. I think static fields live in the Class object, as do all methods. I presume static nested classes have Class objects of their own, referenced from the surrounding class’ Class object, bit I am not certain.



My question does not concern with why java is pure oop language or not,
In all the discussion everybody is telling java is not pure oop because of primitive types(because they are not objects).
What i am asking is static fields and methods are also not related to objects so why we do not give this reason ?
8 years ago
Please explain it to me in detail .
And what is a class level object ?
8 years ago

I have listen this "Java is not pure object oriented because of primitive types",
but what about the static fields ?
Does jvm provides an object for them or not ?
8 years ago