Skip to main content

All Questions

Tagged with
1 vote
2 answers
141 views

Can I use packages without making all of the methods/ attributes public?

I have a project with about 10 classes. I moved some classes to a package for clarity. Is there a safe way to connect between classes without data leaks? -using public is dangerous because anyone can ...
benjamin's user avatar
  • 353
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
0 votes
4 answers
742 views

How to make a member of a class to be accessible only in subclasses in any packages?

How to make a member of a class to be accessible only in subclasses in any packages? Protected is not a solution since it will open the member to other non subclasses classes.
Yaroslav's user avatar
  • 1,325
-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
0 answers
39 views

Visibility of a method in JAVA [duplicate]

I am blocking on this question : Is every instance of Y able to call the method aMethod() of every other instance of Y. The answer I found is NO. package a; class X{ protected void ...
user199's user avatar
  • 107
6 votes
5 answers
2k views

How can a public method return a private type?

Why is it possible to return a private nested class from a public method in a public class? Shouldn't the compiler complain about the return type's visibility being less than the method? public final ...
Monstieur's user avatar
  • 8,092
3 votes
1 answer
152 views

How to access this parameter of an object

So, I have two classes. One class, called Data, and another class, called Part. (It is for an inventory tracking program). Data handles the serialization of info and processing of data for operation ...
Bassinator's user avatar
  • 1,702
0 votes
1 answer
875 views

Accessing child property from Parent class in php

I come from java background and recently testing some OOP methodology in PHP. I found that it is permitted for a parent class to use Child class property. The code below describes what I am trying to ...
Anik's user avatar
  • 2,840
1 vote
2 answers
78 views

Restricting public accessable members - workaround

I want to break my applications model in the logical parts 'Data', 'Commands' and 'Engines'. Everyone outside the application should get a read-only access to the data and access to the commands. With ...
twilker's user avatar
  • 1,427
45 votes
12 answers
16k views

Why can attributes in Java be public?

As everybody knows, Java follows the paradigms of object orientation, where data encapsulation says, that fields (attributes) of an object should be hidden for the outer world and only accessed via ...
strauberry's user avatar
  • 4,199
1 vote
8 answers
5k views

Access private data member from a subclass

I would like to declare a data member of a superclass, private: public abstract class superclass { private int verySensitive; abstract int setVerySensitive(int val); // must be overriden by ...
Regex Rookie's user avatar
  • 10.6k
2 votes
3 answers
2k views

Variable visibility in subclass

This is a very simple question, and I apologize for being so noobish :/ I'm new(ish) to Java. I've got a game on the Market that works quite well, but the code is all rubbish. Basically, I wrote it ...
Snailer's user avatar
  • 3,817
20 votes
12 answers
10k views

the use of private keyword

I am new to programming. I am learning Java now, there is something I am not really sure, that the use of private. Why programmer set the variable as private then write , getter and setter to access ...
LAT's user avatar
  • 291