Hello Nayak
<b>"note that a static method in a class can always use a reference of the class's type to access its members, regardless of whether these members are static or not."</b>
This statement is just Strongly worded. The gist of it is that you CANNOT access non-static members of a class from a static method.
The only way out though is through an instance. Think about it. Can you access a class's non-static variable or a method witout first instatntiting the class from your main method, which by the way is static.
consider this simple class
<CODE>
public class A {
public static void staticMethod() {
System.out.println("Inside Static Method");
}
public void instanceMethod() {
System.out.println("Inside Instance Method");
}
public static void main(
String [] args) {
A.staticMethod(); // can access it because it is a static method
staticMethod(); // can still access it, because static methods can
// access other static members of the same class
// without qualifying them with the class name
instanceMethod(); // CANNOT! Because static methods cannot invoke or
// other non-static members
A a; // COMPILES
a.instanceMethod(); // Compile time error. a might not have been
// initialized
A.instanceMethod(); // CANNOT! Because it is not a class method
// Compile time Error
// non-static method cannot be referenced from
// a static context
A x = new A(); // Create a new instance of the class
x.instanceMethod(); // WE CAN! Through An Instance
} // END OF MAIN
} // END OF CLASS
</CODE>
Now for the second statement
<b>Static methods cannot be overridden. They can only be hidden.</b>
static methods are class methods.They provide services on behalf of the class. You do not need an instance of the class to access a static method.
Now, if a class declares a static method as abstract which does not have any implementation, then how can it provide a service on behalf of the class?
It cannot, Right?
So, there we are, you can't declare a static method as abstract.
IT IS A COMPILE TIME ERROR.
JDK 1.4 responds thus when i compile staticExample.java
<CODE>
abstract class simpleClass{
abstract static void method();
}
public class staticExample extends simpleClass{
static void method(){
System.out.println("Method in base class");
}
public static void main(String [] args){
staticExample s = new staticExample();
s.method();
}
}
</CODE>
Compiler Response
C:\JavaPrograms\staticExample.java:2: illegal combination of modifiers: abstract and static
abstract static void method();
^
1 error
Hope this helps
am i right?