alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (QualifiedAccess_3.java)

This example Java source code file (QualifiedAccess_3.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

bar, baz, cmain, error, foo, quem, quux, type

The QualifiedAccess_3.java Java example source code

/**
 * @test  /nodynamiccopyright/
 * @bug 4094658 4785453
 * @summary Test enforcement of JLS 6.6.1 and 6.6.2 rules requiring that
 * the type to which a component member belongs be accessible in qualified
 * names.
 *
 * @compile/fail/ref=QualifiedAccess_3.out -XDrawDiagnostics QualifiedAccess_3.java
 */

import pack1.P1;

class CMain {

    class Foo {
        class Bar {}
    }

    static class Baz {
        private static class Quux {
            static class Quem {}
        }
    }

    // These are all OK.
    CMain z = new CMain();
    Foo x = z.new Foo();
    Foo.Bar y = x.new Bar();

    void test() {
        P1 p1 = new P1();

        // These are NOT errors, and should NOT be detected, as observed.
        /*------------------------------------*
        Baz.Quux z = null;
        Baz.Quux.Quem y = null;
        *------------------------------------*/

        P1.Foo.Bar x = null;            // ERROR - 'P1.Foo' not accessible
        int i = p1.a.length;            // ERROR - Type of 'a' not accessible
        // The type of the expression from which a component
        // is selected must be accessible.
        p1.p2.privatei = 3;             // ERROR - Type of 'p1.p2' not accessible.
        System.out.println (p1.p2.privatei);    // ERROR - Type of 'p1.p2' not accessible.
    }

}

Other Java examples (source code examples)

Here is a short list of links related to this Java QualifiedAccess_3.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.