Skip to main content

All Questions

-2 votes
1 answer
504 views

Protected variable not accessible within child class in Java

I have the following structure - App.java - package JohnParcellJavaBasics.AccessModifierDemo; import JohnParcellJavaBasics.AccessModifierDemo.*; public class App { public static void main(String[]...
Payel Senapati's user avatar
0 votes
1 answer
62 views

Package-private member visibility in complex inheritance / package combinations - Qiuck General Rule to verify visibility

If Base and Derived classes are in different packages then package-private member from Base shall not be inherited and thus it shall be absent in Derived, that is such member shall be inaccessible ...
Code Complete's user avatar
1 vote
2 answers
61 views

Java: protected, visibitily [duplicate]

I'm a bit confused about the whole protected thing in java. If something is protected only the classes within the same package can access it, right? Should we use protected private attributes in a ...
user8716414's user avatar
5 votes
3 answers
4k views

Java: calling a super class' protected method from a subclass - not visible?

I am calling a super class' protected method from a subclass. Why is this method "not visible"? I've been reading some posts such as this one, that seem to contradict the following: Super class: ...
rapt's user avatar
  • 12.1k
-1 votes
2 answers
1k views

Why can protected attributes be accessed by other classes of the same package [duplicate]

Why do protected attributes in a Java class can be accessed by the other classes of the same package ? I thought it was only accessible through inheritance. A.java package abc; class A { ...
Libert Piou Piou's user avatar
0 votes
1 answer
761 views

Why is a protected variable visible at class level? [duplicate]

A protected variable is access to any class within a package and only to a subclass that extends the base class outside the package. Why did Java implemented this in this was i.e default within ...
user892871's user avatar
  • 1,025
1 vote
0 answers
32 views

Why cannot I see third party protected members of parent? [duplicate]

I noticed strange behaviour of access modifier package protected_test.pack1; public class Source { protected int protectedInt= 1; } package protected_test.pack2; import protected_test....
gstackoverflow's user avatar
2 votes
3 answers
836 views

Overrided method visibility in Java

Assume that we have a package "p1": package p1; public class A { protected void method() { } } ... and we also have a package "p2": package p2; import p1.A; public class B extends A { } ...
Ilya Gubarev's user avatar
45 votes
6 answers
17k views

Understanding Java's protected modifier

I have a class called A in package1 and another class called C in package2. Class C extends class A. A has an instance variable which is declared like this: protected int protectedInt = 1; Here is ...
mahela007's user avatar
  • 1,429
1 vote
5 answers
2k views

How to implement an interface on a protected java class

I was looking to implement an interface on a package-private java class, but I am having some difficulty achieving this. Below is an example. class Foo { String something(String str) { ...
andersra's user avatar
  • 1,135
3 votes
5 answers
7k views

Java Protected Access Not Working

In java, there's three levels of access: Public - Open to the world Private - Open only to the class Protected - Open only to the class and its subclasses (inheritance). So why does the java ...
Anton's user avatar
  • 1,427