I was reading about protected modifier in Java which fields can be accessible inside same package and subclass.
Now I have written some code.
package com; public class Parent { protected void print() { System.out.println("dFDF"); } } Now subclass.
package abstraact.concept; import com.Parent; public class BaseParent extends Parent{ public void printNum() { Parent p = new Parent(); p.print(); /** Getting error here */ // The method print() from the type Parent is not visible } public static void main(String[] args) { BaseParent pp = new BaseParent(); pp.printNum(); } } Why I am getting error? Since protected method/variables are accessible from subclass.