A toplevel class certainly can be static. Static has nothing to do with the level of a class.
it can access in entire application.
Declaring an inner class static means that class only has access to the "outer" class public and private static fields. A non-static inner class has access to the outer class's instance data. Top-level classes cannot be declared static. The advantage of a static inner class is that it doesn't need an instance of the containing class to work and it's bytecode class size is smaller for that reason - less overhead.
A class that is declared as "final" cannot be inherited.
A static class is a class where all the members are declared static.
There is no separate entity as a static object in java. The static keyword in java is used to signify that the member (either a variable or a method) is not associated to an object instance of the class. It signifies the fact that the member belongs to the class as a whole. The words static and objects are opposites of one another so you cannot have a static object. However, you can declare an object as a class level variable which could be referred to as a static object but it will be referred to as a static or class variable and not a static object.
Static functions are tied to a class, not to a particular object. A static function can only access static variables because it has no knowledge of member variables.
No. You will get compilation errors. The complier will complain that you are trying to access non static variables from inside a static method. A static method can access only static variables.
Because, the keyword static signifies the fact that the method or variable that is qualified using the static keyword is not attached to any object of the class. Therefore we cannot instantiate the class and use the object to reference to access it. The only option we have is to use the class name to directly access them
Because of the following reasons:static - If a constructor is static, an object instance cannot invoke it to initialize itself (Because static members are not linked to an object)abstract - because an abstract class cannot be instantiated and hence it will not have a constructor. If you make a concrete class's constructor abstract - it cannot be instantiated. eitherways it makes no sensefinal - a constructor cannot be final (thats the way java is designed)
A static class may or may not have static members. Adding the static keyword to the class definition won't change this. Note that an inner class which is not static may not contain static members (unless those members are also declared final).
Static MethodsStatic keyword when used with a method, specifies that this method belongs to the class and not a particular instance of the class (a.k.a object of the class)Ex:public class StaticTest {public static String getAuthorName() {return "Anand";}}Here getAuthorName is the static method and it can be accessed without instantiating an object of the class StaticTest. You can access this method as:String authorName = StaticTest.getAuthorName();Tip: It is important to know that, a static method cannot and I mean CANNOT access instance variables or methods of the class. It can only access other static methods and variables.For Ex:public class StaticTestBad {private String name = "Rocky";public static String getAuthorName () {return name; //Cant work!!!}public int getAge(){return 28;}public static int getAuthorAge() {return getAge(); //Cant Work Again!!!}}If you try to compile this class, you will get compilation errors at the two lines that I have commented out.Static VariablesThe static modifier tells the system that this particular variable belongs to the class and does not belong to any specific instance of the same. The class will contain only one instance of the static variable irrespective of how many objects of the class you create.
by creating class as an static class