Skip to main content

All 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 ...
grecode97's user avatar
-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
-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) { ...
rahul sharma's user avatar
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 ...
minseong's user avatar
  • 11.7k
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
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 ...
pedrorijo91's user avatar
  • 7,775
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 ...
manav saxena's user avatar
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 ...
Tony's user avatar
  • 1,145
-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 ...
The Coding Wombat's user avatar
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; } ...
Mohammed Aouf Zouag's user avatar
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 ...
Eusebius's user avatar
  • 531
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
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"; ...
Bhuvan's user avatar
  • 4,148
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
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(...
eightShirt's user avatar
  • 1,451

15 30 50 per page