why top level class could not be static

Answer Posted / vatsal doshi

The answer is in the question itself.
What is static? Something which belongs to a class and not its objects.

So if in a class, we have some variables, having single copy, we call them static.
Similarly some methods may be actually manipulating these static variables, so those methods are also static.

However, the class itself is static only if it belongs to some class(Definition of static)

So, for a class to be static, it must be a nested class. Such nested classes are called as Top Level Nested Classes in Java.

Is This Answer Correct ?    7 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is keyword auto for?

637


Say any two properties in beans?

632


Can a class extend more than one class?

607


Explain about main() method in java ?

580


What is keyset in java?

653






What is a parameter used for?

512


What is the difference between a method and a procedure?

541


Why we override equals() method?

559


What is the purpose of interface?

577


Write an algorithm program in java for the following question.. 1) S is a set of integers.X is an integer obtained by sum of two digits in S. Write logic for whether or not the X is from the S. The time of algorithm should not exceed o(n logn).

1602


What is an exception in java?

644


How does hashset works in java?

528


Why java is said to be pass-by-value ?

544


What is a string what operation can be performed out with the help of a string?

504


Wha is the output from system.out.println(“hello”+null); ?

688