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 ***

Friday, January 22, 2010

20 - non public class and public method - level very basic - Java 1.6.0_17 - NB 6.8

OK it's for newbies...

But is it clear in your mind ?
If the class is not public even if the method is public you can't use the method !

package javaapplication10;

class Main { // where is public ???

    public void a() { // it is public !!!
        System.out.println("a");
    }

    public static void main(String[] args) {
        new Main().a(); // here you can
    }
}

package newpackage;

import javaapplication10.Main; // DOES NOT COMPILE !

public class Test {

    public static void main(String[] args) {
        new Main().a(); // DOES NOT COMPILE !

    }
}

No comments:

Post a Comment

Followers