Skip to main content
How are we doing? Please help us improve Stack Overflow. Take our short survey

All Questions

Tagged with
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
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 ...
Joe23's user avatar
  • 5,752
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 ...
fredoverflow's user avatar
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 ...
Monstieur's user avatar
  • 8,092
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 ...
Kevin Murvie's user avatar
  • 2,632
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 ...
Eugene's user avatar
  • 59.9k
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 ...
Opoe's user avatar
  • 1,387
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, ...
Michael McGowan's user avatar
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; [...]...
pek's user avatar
  • 18k
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 ...
Lukas Eder's user avatar
  • 218k
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 ...
BalusC's user avatar
  • 1.1m
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
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
9 votes
2 answers
30k views

package visibility [closed]

Why use package visibility (the default), unless the class should be public in java
Nivedha's user avatar
  • 137
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 ...
Adith's user avatar
  • 175

15 30 50 per page
1
2 3 4 5