Tagged Questions
0
votes
3answers
51 views
MultiThreading with instance variable java
I have a class like,
Class A extends B {
String test = "";
String first = "";
public void testMethod() {
new Thread() {
public void run() {
testThreadMethod();
...
0
votes
1answer
16 views
Creating a field that calls a method
Hi I asked a question a few days back about a Jbutton and a method it's calling. I got an answer about putting the method into a field, so i tried this but I'm met with a null pointer.
private ...
-1
votes
2answers
52 views
Java -What is an instance variable? [closed]
I have to do a program in which an instance variable which is a String should be inputted ( is that a word?) by the user. What is an instance variable?How do I create one? and what does it do? Keep it ...
0
votes
3answers
158 views
What is the difference between an instance and a class (static) variable in Java [closed]
The title of this question is actually a previous examination question and I am looking for clarification / an answer to it.
Please note that I am learning Java and am becoming familiar with its ...
4
votes
5answers
230 views
Variable and Method shadowing in Java
Basically I would like to know why a static method cannot be shadowed by an instance method, (I know why, it will lead to ambiguity in certain circumstances), whereas a static variable can be shadowed ...
4
votes
7answers
6k views
why instance variables in java are always private
I'm newbie to Java and i'm learning about encapsulation and saw an example where instance variables are declared as Private in a class.
http://www.tutorialspoint.com/java/java_encapsulation.htm
...
9
votes
4answers
260 views
Inheritance: object creation
Let's say I have this piece of code:
class Animal {
int legs = 4;
int head = 1;
}
public class Dog extends Animal {
public static void main (String []args) {
Dog dog = new Dog();
...
0
votes
1answer
40 views
learning to crate object and access methods inside the class how can i..?
my execution shows this error:
java.lang.NoSuchMethodError: main
I need to get students detail as output. The program should access all the above methods. Please help.
import java.io.*;
...
1
vote
2answers
349 views
Instance Variables in Stateless Session Bean - state is maintained how?
Server running on GlassFish 3.0
@Stateless(mappedName="messengerservice")
public class MessengerService implements MsnService{
int count;
@Override
public int getCount() {
// ...
0
votes
3answers
63 views
How do I add an instance of a class without the constructor's parameters?
I'm trying to create a fantasy football draft program. The first step I'm having a hard time is reading the data into a List properly. I want to scan the data, line by line. I created a loop that sets ...
1
vote
5answers
62 views
Instance Variable only in one row in Java
Hi stackoverflow members,
Do you know why an instance variable in a Java Class must be declared only in one line and not in 2?
for example:
String ring;
ring = "indeed";
It gives a compilation ...
10
votes
9answers
9k views
Java Instance Variables vs Local Variables
I'm in my first programming class in high school. We're doing our end of the first semester project. This project only involves one class, but many methods. My question is best practice with instance ...
3
votes
4answers
111 views
Accessing instance members in constructors
I read in a book that instance members are accessible only after the super constructor runs.
I stumbled upon the following code:
class Parent {
Parent() {
printIt();
}
void ...
2
votes
2answers
172 views
Design Issue: Static vs Non-static instance variables
I am designing an Address Book and in order to make my AddressBookApp class work (which includes my main method) I have had to create instance variables and make them static in order for each method ...
19
votes
8answers
9k views
Instance variable initialization in java
I have doubt in instance variable initialization in java.I have seen different developers initializing varibles differently.In the below sample codes what is better way.Do we have any advantage of ...