All Questions
Tagged with visibility java
66
questions
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 ...
34
votes
7
answers
8k
views
How to demonstrate java multithreading visibility problems?
If variables in Java are accessed from multiple threads, one must ensure that they are safely published. This usually means using synchronizedor volatile.
I have got the impression, that some of my ...
51
votes
9
answers
24k
views
public methods in package-private classes
Does it make a difference to mark methods as public in package-private classes?
class SomePackagePrivateClass
{
void foo(); // package private method
public void bar(); // public ...
25
votes
3
answers
21k
views
Why can I override a protected method with public method?
The Java compiler doesn't complain when I override a protected method with a public method. What's really happening here? Is it overriding or hiding the parent method since the parent method has lower ...
4
votes
2
answers
3k
views
Android - RecyclerView with one layout, multiple setVisibility
I have a basically all in one layout which has everything needed for my app's main feed. All variable items (images, video thumbnails.. Etc.) are set to GONE at first and set to VISIBLE when it is ...
22
votes
7
answers
37k
views
Aren't Java constructors public by default? [duplicate]
I have two classes in two different packages. For one class I've defined a constructor without setting access modifier for it. I want to instantiate an object of this class in another package and get ...
2
votes
2
answers
23k
views
Java swing; How to toggle panel's visibility?
i made this code to navigate trough panel1 and panel2
with buttons.
(button1 and button2) but when i run my code the frame stays empty.
Can somebody explain me what i'm doing wrong and how i can ...
82
votes
3
answers
11k
views
Why is there no sub-class visibility modifier in Java?
On more than one occasion I have found myself desiring a variable visibility that is not possible in Java. I wanted certain members to be visible within their own class and within any sub-classes, ...
17
votes
6
answers
4k
views
Java Private Field Visibility
So I was making a class the other day and used Eclipse's method to create the equals method when I realized that it generated the following working code:
class Test {
private int privateInt;
[...]...
5
votes
3
answers
1k
views
How to fully qualify a class whose package name collides with a local member name?
OK, here's a very curious Java 7 language puzzle for the JLS specialists out there. The following piece of code won't compile, neither with javac nor with Eclipse:
package com.example;
public class ...
45
votes
1
answer
2k
views
Type-parameterized field of a generic class becomes invisible after upgrading to Java 7
Now Eclipse Indigo SR1 with builtin Java 7 support is finally out since a week or two, I'm migrating my playground projects from Helios SR2 + JDK 1.6_23 to Indigo SR1 + JDK 1.7.0. After a full rebuild ...
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 ...
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";
...
9
votes
2
answers
30k
views
package visibility [closed]
Why use package visibility (the default), unless the class should be public in java
9
votes
4
answers
14k
views
setvisible method in java swing hangs system
I have banking gui application that I am currently working on and there seems to be a problem with the setvisible method for my jdialog. After the user has withdrawn a valid amount I pop up a simple ...