This is some information on the Java 6 certification that I prepare. This information is not very well structured and it is most of the time an answer to the questions that come when I read the SCJP 6 book (Bates and Sierra). *** AS OF 5 OF MARCH 2010, I AM SCJP 6.0 ***

Monday, January 11, 2010

8 - Abstract classes and static methods

Abstract classes can have static methods and you are able to execute those methods !



public abstract class AbstractClass {
    private static String version = "0.0.1";

    static String getVersion() {
        return version;
    }
}


public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        //new AbstractClass(); // you can't because the class is abstract
        System.out.println("" + AbstractClass.getVersion()); // no problem you can execute a static method !
    }

}


run:
0.0.1


No comments:

Post a Comment

Followers