This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 229429 - Protected keyword does not work
Summary: Protected keyword does not work
Status: RESOLVED INVALID
Alias: None
Product: java
Classification: Unclassified
Component: Compiler (show other bugs)
Version: 7.3
Hardware: PC Windows 8 x64
: P1 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-07 01:09 UTC by Richard_Lin
Modified: 2013-05-07 07:35 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard_Lin 2013-05-07 01:09:36 UTC
Overview: 
Object can use a protected method from another class when it is not a subclass.

Steps to Reproduce:
1) Make three Java class files. Name them Example, Example2, and Example3.
2) Type each of these classes into the corresponding files:

public class Example {

    public static void main(String[] args) {
        Example2 b = new Example2();
        Example2.a c = new Example2.a();
        Example3 d = new Example3();
        b.ddp();
        c.ddp();
        d.ddp();
    }
}

public class Example2 {

    protected void ddp() {
        System.out.println("ohio");
    }

    public static class a {

        public void ddp() {
            System.out.println("ohio");
        }
    }
}

public class Example3 extends Example2 {
}

3) Run the code.

Actual Results: The console prints out 3 ohios.
Expected Results: There should be a compiler error since the method Example2.ddp() is protected and object b should not be able to use it since Example is not a subclass of Example2.

Build Date & Platform: Build 2013-05-06 on Windows 8
Comment 1 Jiri Prox 2013-05-07 07:35:26 UTC
The classes are in the same package
http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html