All Questions
23
questions
1
vote
1
answer
309
views
Do inherited methods use the visibility, methods and attributes of the superclass or subclass?
What I assume is that an inherited method will, by standard, use the methods and attributes of the class whose object is used to execute that method.
Here's an example for my question, it's from a ...
-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[]...
-1
votes
3
answers
416
views
Java Overridden method visibility scope
How is the following program correct?
abstract class Calculate
{
abstract int multiply(int a, int b);
}
public class Main
{
public static void main(String[] args)
{
...
0
votes
1
answer
375
views
protected method vs protected property
Subclasses need to be able to use the seeded random number generator.
What are the pros and cons of using
public abstract class AbstractClass {
protected Random rnd;
public AbstractClass(long ...
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 ...
0
votes
1
answer
499
views
Java method that can't be callable but can be overridden
If I don't want that a method on my class can be called, I just make it private.
But if I want to allow that method to be overridden, I have to make it protected
Is it possible to have a method on ...
1
vote
4
answers
680
views
Java Inheriting a public class with Package Private Constructor
I come from a C++ background, I was just going through Access-Modifiers in Java and I decided to play around with some code and now I am getting an error:
YouArePublic() is not public in ...
1
vote
3
answers
67
views
How to prohibit a subclass from having a method?
In my Java project, I have the method addType1AndType2() which has windows where you expand lists and select objects from the list. It was very complicated and time consuming to create, as things must ...
-1
votes
2
answers
66
views
Visibility of class variables in parent class
I have a class Player.java which extends Entity.java. In entity I define the x and y coordinates. In Game.java I create a player object: Player player = new Player(0, 0);. What should the visibility ...
0
votes
4
answers
233
views
Subclass member variable's visibility to another subclass
I am running a test program to know more about member variables' visibility, and I created the following 3 classes:
ParentClass.java
public class ParentClass {
protected int mMember;
}
...
0
votes
2
answers
928
views
Limit visibility to subclasses only in Java [duplicate]
In Java, the protected keyword limits the visibility of a field or method to the subclasses and the whole package.
Is there a way to limit the visibility only to subclasses, in a static way (i.e. at ...
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 ...
18
votes
3
answers
3k
views
Why can we reduce visibility of a property in extended class?
I have two classes, Parent:
public class Parent {
public String a = "asd";
public void method() {
}
}
And Child:
public class Child extends Parent{
private String a = "12";
...
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....
0
votes
2
answers
85
views
Another "cannot find symbol"
I´m getting cannot find symbol error in my code (symbol: method setAr(boolean)).
Here is my Main.java file:
class Vehicle {
protected int marchs;
protected int rode;
public void xydar(...