variable « private « Java Class Q&A

Home
Java Class Q&A
1.abstract class
2.Base class
3.class hierarchy
4.class name
5.class version
6.Class.forName
7.ClassCastException
8.Clone
9.constant
10.Constructor
11.Development
12.DTO
13.encapsulation
14.equal method
15.extend Class
16.getter
17.hashcode
18.Inheritance
19.inner class
20.interface
21.main class
22.Method
23.NoClassDefFoundError
24.NoSuchMethodError
25.NoSuchMethodException
26.object reference
27.overload
28.parent class
29.Polymorphism
30.private
31.Private Field
32.Recursive
33.setter
34.Static
35.Static Class
36.subclass
37.Super
38.toString
39.Wrapper Class
Java Class Q&A » private » variable 

1. java inner/outer class questions about outer class private variables access    stackoverflow.com

I have the following java class:

class Outer
{
    private Integer a;
    private Long b;

    class Inner
    {
    ...

2. Having access to a private variable from other classes in Java    stackoverflow.com

If I want to create a form that adds people to a List, how do I have access to that List from another class? Where would I define that List ...

3. error in this line :"private String[][] variable=new String[][] {var1,var2,var n}"    stackoverflow.com

my question is im getting d jtable but i want to display the data from the database into the the jtable. if i pass data directly its being displayed in the jtable ...

4. Reading from variables that are located in a private method    stackoverflow.com

I am having a small problem I am trying to print the contents of a couple of variables which are located in a a private method. but I simply keep getting ...

5. Why can I access a private variable from main method?    stackoverflow.com

package com.valami;

 public class Ferrari
 {
  private int v = 0;


  private void alam()
  {
   System.out.println("alam");
  }

  public Ferrari()
  {
   System.out.println(v);
 ...

6. Java anonymous class and reachable private variable    stackoverflow.com

interface Test {
public void test();
}

public class TestMain {
private String h = "AAA";

public static void main(String[] args) {
    TestMain t = new TestMain();
}

public TestMain() {
    Test ...

7. access private variable from other class in java    stackoverflow.com

i hope that i mean my words. i have a class like this:

public class MainClass extends JFrame{
    private JLabel mainlabel;
    private SampleClass sample=new SampleCalss();

   ...

8. what is the concept of private variable    coderanch.com

The point of a private variable is that you can only get it by calling a method. This means that the class is free to change the way it stores the information, without hurting other classes. Imagine we have a class: class T1 { public String url; } and another class uses it like: T1 myt1; myt1.url = "http://www.javaranch.com/"; System.out.print(myt1.url); We ...

9. keeping variables private in a bean.    coderanch.com

I have got a bean CraneAsset, which extends Asset. "Asset" has a property called "assetNum" and appropriate get/set methods. When I create a CraneAsset bean and use getAssetNum, I got a message that "assetNum" is a private variable in the superclass "Asset". So I went back to the "Asset" and changed "assetNum" to "protected". But making it "protected" to get "assetNum" ...

10. Accessing private class variables...    coderanch.com

Ok lets say I have a class called AltTreeMap. In that class one of the class variables is: private Node root. Now in my node class I want to access the root in this fashion: if (root==null).. how do I do this? If I try using this.root the compiler thinks "this" refers to a Node, not to the AltTreeMap class. If ...

11. how can private provide security for variables    coderanch.com

indeed. There is a strong school of thought that says you shouldn't generally have setters at all, just getters, and set every field through the constructor only (essentially making as many objects immutable as possible). You could say you're providing the option of increased security when using setters as you can write them to provide for example validation (or even authorisation), ...

13. private variables and accessor methods?    coderanch.com

Can someone explain to me the logic behind making varaiables private (so that other classes CAN NOT access or change the variables) and then adding accessor methods (so that other classes CAN access or change the variables)??? I don't get it? There has to be a reason because it is in every JAVA book I am reviewing. But, it appears inherently ...

14. What is the Right Way (TM) to access private variables?    coderanch.com

This is a question about programming style. Everyone knows that encapsulating your variables is a Good Thing (TM). Obviously one class wants to access another class's private variables, it must do so via getter/setter methods. My question is this: When a class wants to access its own private variables, should it do so via getter/setter methods or directly? On the one ...

15. Accessing private variable    coderanch.com

public class Obj { private int val = 0; public int getVal() { return val; } public void changVal(Obj o) { o.val = 3; } public static void main(String[] args) { Obj o1 = new Obj(); Obj o2 = new Obj(); o1.changVal(o2); System.out.println("o1:" + o1.val + " o2:" + o2.val); } }

16. Declaring Multiple Private Variables    coderanch.com

This question is either really naive or just not possible Here is what ive typed into Jcreator Pro: //VARIABLE TO HOLD Candidate CHOICE private int choice = 0; count1; count2; count3; count4; count5; count6; count7; maxVote; My question is, when having multiple variables am I to use ";" just to separate them or after the private int choice = 0 am ...

17. Using get/set vs. direct access to private variables    coderanch.com

Generally, if you are within the same class, the convention is to access the instance variable directly. An exception to this might be if the getter did some sort of error checking, and you wanted that error checking to occur each time you use the instance variable; then that work could be centralized in the getter, and the getter would be ...

18. Accessing private variables in equals()    coderanch.com

Hello, I am trying to compare two objects by overriding equals(Object o) method. Code: public class TestEquals{ private int a; private int c; private boolean val=false; public boolean equals(Object o){ TestEquals te=null; if(o instanceof TestEquals) { te = (TestEquals)o; if((this.a==te.a)&&(this.c==te.c)) val=true; else val= false; } return val; } How can I access private variables a&c using te.a and te.c?? I thought ...

19. got private variables :(    coderanch.com

20. Private variable problem    coderanch.com

Hi All, I want to access a varible form my super class. But i am having problem to access that. Below is my code : public class A { Private int price=0; } Public class B extends A { public int getPrice() { return price; } } If i declare varible as 'Private' then i am not able to access it ...

21. Accessing private variables directly from outside the class    coderanch.com

Hi, Please have a look at the code below. public class Person { private String name; public Person(String name) { this.name = name; } public static void main (String[] args){ new Person("Java").equals(new Person("Java")); } public boolean equals(Object o) { if ( ! (o instanceof Person) ) return false; Person p = (Person) o; p.name = "andy"; return p.name.equals(this.name); } } This ...

22. Private variables and get/set    coderanch.com

Hello all, I'm a little bit confused about this: I know that private istance variables are non heritaged but public method yes. So if I had two classes like this: public class Person { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } public class Employee extends Person { private ...

23. Access Private Variables outside the class?    coderanch.com

Without reflection it's not possible from outside the outer most class. Private members of a nested class are visible in its enclosing class. For example: class Test { static class Test2 { private static final int i = 13; } public static void main(String[] args) throws Exception { System.out.println(Test.Test2.i); // compiles since Test2 is nested within Test } } class Test3 ...

24. Visibility of private variables    coderanch.com

25. Why make class variables private?    java-forums.org

Okay, so I keep coming across the practice of making class variable private and using getter and setter methods for other classes to interact with these variables. I tried looking for some explanations but what I have found is that it is "good practice" to do so. However, as I code, sometimes I find my code is longer and it is ...

27. Why do we declare the variables private in a bean    forums.oracle.com

Hi^^, thank you for the article you have supplied. Two lines used in the article are interesting.They are as follows: 1.Information hiding serves as an effective criterion for dividing any piece of equipment, software or hardware, into modules of functionality. 2.When a computer program is well designed decomposing the source code solution into modules using the principle of information hiding, evolutionary ...

28. private variables    forums.oracle.com

How to access private variable of a class in other class ? the deeper meaning of private members (=variables) is that they are NOT accessible from another class. if you want to do that, you have to use Introspection to temporarily change from private to public, do your access, and then restore private state. Thats the way spring does such things. ...

29. private variable issues    forums.oracle.com

I looked at your hello and Goodbye test class and did guess "hello". I am pretty sure that with a few tricks I will hopefully be able to keep some of the variables private access. My original example is pretty average so for that i apologise. Its hard to explain the problem im having since the program is a work in ...

31. Private class variables    forums.oracle.com

Hi I am developing an application which simulates a University. I have to read in data from a file, the data which i am having problems with is a private class variable which keeps track of the number of lecturer objects. I am reading the data in from a different class from the one which stores the class variable. Whats the ...

33. question about private variables    forums.oracle.com

34. How to access private variables of another class?    forums.oracle.com

Saish is a very helpful person. I remember one time when I asked his advice about how I should tackle a difficult problem. "Should I program to interfaces? Should I use RMI-IIOP over Banyan Vines with LU 6.2? What about NetBeans? Who played Whitey on 'Leave It To Beaver?' I just don't know what to do, Saish!" and he said, " ...

35. Trouble declaring a private variable    forums.oracle.com

36. Trouble declaring a private variable    forums.oracle.com

38. Private Variables    forums.oracle.com

What is the use in declaring a variable as private . Because if the user has to modify the variable we have to provide the user with get and set methods . He will declare an Object of that class and calls set /get methods. Instead we could have declared that variable as public and allow him to change directly?Is it ...

39. Private variables outside class    forums.oracle.com

40. class as a private variable of another class: how inefficient is that ?    forums.oracle.com

Well, the syntax isn't correct so that won't even compile. And no, it's not inefficient. You don't have a clue about the real bottlenecks in applications (network, database, etc.) if you're worried about having classes as member variables. Or did you plan on using only primitive values for your programs? Then you're using the wrong language, you want C.

41. one obj manipulates private variable of different obj    forums.oracle.com

azjp wrote: Now. the following contradicts my perception that private instance methods can be accessed from within any instance method of an object of the same class. No it doesn't. It just a) invalidates your assumption that calling a method via reflection is identical to calling it normally, and/or b) shows that you didn't read the docs for getMethod(), getMethods() closely ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.