All Questions
22
questions
0
votes
0
answers
34
views
Initializing Array size to the size that is initialized in constructor throws ArrayIndexOutOfBoundsException [duplicate]
I'm trying to create a Shelter Class, where i can shelter Animals(which is another class that has two extensions Catg,Dog) but when i initalize the shelter's size with a constructor and then ...
0
votes
0
answers
89
views
variable reassignment issue in java
I have my code behaving the way I'm expecting it to behave except for one last issue. In the while loop within void main() while (gameStatus == Status.CONTINUE) I'm trying to set the variable ...
0
votes
0
answers
196
views
How to access child class variable from parent class during runtime?
I have multiple child classes that extend a parent class.
Parent Class:
Class ParentClass{
public void printMessage() {
Reporter.log("Child Class Name at Runtime = " +this.getClass()....
-2
votes
1
answer
133
views
What happens to classes in Java Program when the program runs? [closed]
I was reading about Nested classes and especially inner classes where I came across the problem of defining a class inside the scope of for-loop.
What I know so far is that class is a type and we ...
1
vote
2
answers
339
views
'this' inside of a BukkitRunnable
What does the this keyword refer to inside an org.bukkit.scheduler.BukkitRunnable?
public class Foo {
protected Player player;
public Foo(Player player) {
this.player = player;
...
1
vote
1
answer
1k
views
How to pass variables to a Thread's Runnable created with lambda as an anonymous function?
Either IntelliJ isn't intelligent enough and confuses me or it's more likely there's something that I'm missing about scopes of variables in Java (or the concept of OOP). I have this piece of code:
...
3
votes
4
answers
3k
views
OOP questions, i.e. where to put the separate classes?
I am working on using separate classes in a Object-Oriented Programming program.
Would you create the separate class and the program itself in separate .java files or the same?
As in:
public class ...
2
votes
2
answers
79
views
Why does my custom member variable of a class not update in other classes?
So I'm working on a project and I need to design a game that has a player. Inside the Game object, I've initialized a player and set a getter for this player:
The player knows only of its own ...
5
votes
4
answers
230
views
java referencing objects that are not in scope
one question that always pops up when my java project gets bigger is if there is an easy way of making references to a specific object thats cannot be referenced by super or getParent(). The following ...
3
votes
1
answer
670
views
Java using "extends" with scope-resolution/"dot" operator?
I just came across this while reading some code and I have absolutely no idea what it means. I tried googling and whatnot but I got nothing, probably due to a lack of vocabulary. The code:
public ...
1
vote
2
answers
68
views
Why won't variabes from other methods return to the main method? (more inside)
The purpose of this program is to print
the number of solutions and the solution(s) to a quadratic function,
entered by the user.
The problems here is that I get errors for having private variables,...
1
vote
1
answer
2k
views
Protected Variables aren't allowed by default in Checkstyle, but what about in an enum?
I'm using Java in eclipse, and I read a thread
I really liked home's answer, because I never really thought about it before. The whole idea that subclasses should really not have access to members ...
1
vote
3
answers
94
views
Method Local Inner Class Member scope access
How do I access the method variable having the same name as the inner class member instance or method local variable of the inner class?
class A{
int a = 10; //1
public void ...
0
votes
2
answers
764
views
How to use a variable from a method (inside Try-Catch) in another class?
So I'm trying to create a basic RPG userID selection menu using JFrames; I opted to display the ID options using radio buttons. Once the user selects and ID I burp it back using a JOptionPane. All ...
4
votes
2
answers
134
views
Pass outer anon class ref to a method in an inner anon class
How to pass outer anon class ref to a method in an inner anon class in Java?
I have a method that makes async call to a server - sendCall(some_args, callback). The callback is represented by ...