Protected nested class not accessible to derived classes in other package

Viewed 2226

Here is what I'm trying to accomplish

File 1: ./net/Class1.java

package net;

public class Class1
{
    protected static class Nested
    {

    }
}

File 2: ./com/Class2.java

package com;

import net.Class1;

public class Class2 extends Class1
{
    Nested nested = new Nested();
}

Here is the error I'm getting

>javac ./net/Class1.java ./com/Class2.java
.\com\Class2.java:7: error: Nested() has protected access in Nested
        Nested nested = new Nested();

Is this error expected? Am I doing something wrong?

1 Answers
Related