
can we access protected data members of base class in derived class directly

Access Protected Members
Yes, you can.
Here is an example:
class Protected{
protected int num=5;
protected void protectedMethod() {
System.out.println("Hello");
}
}
class AccessProtectedMembers extends Protected{
public static void main(String[]args){
AccessProtectedMembers a = new AccessProtectedMembers();
System.out.println(a.num);
a.protectedMethod();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.