Home Answers Viewqa Java-Beginners how to pass class variable to another class

 
 


raja
how to pass class variable to another class
1 Answer(s)      2 years and 6 months ago
Posted in : Java Beginners

i need to access a variable from a class to another class currently running at the same time.

using Classname.variable i got the value. But when i change the value second time i got the previous value. I used static variabe.

View Answers

December 1, 2010 at 12:59 PM


Hi Friend,

Try the following code:

 import java.util.*;
 class A {
    static int regd;
    static int a;
    public static int get() {
Scanner input=new Scanner(System.in);
System.out.print("Number:");
regd=input.nextInt();
a=regd;
return a;
    }
    }

 public class B {
     static int b=A.get();
     public static void main(String[]args){
     System.out.println(b);
     }
     }

Thanks









Related Pages:
how to pass class variable to another class
how to pass class variable to another class  i need to access a variable from a class to another class currently running at the same time. using... the following code: import java.util.*; class A { static int regd; static int
How to pass variable from one class to another in java
How to pass variable from one class to another in java  How to pass variable from one class to another in java?   Example: public class...; } } //Another class Class2. public class Class2 { public static void main(String
how to pass a string from one class to another
how to pass a string from one class to another  hi all, Good morning. I am trying to develop a coding pass a string from one class and declare in other class. the string which i need to pass is the data from an file and i want
ArrayList as an argument to another class
ArrayList as an argument to another class  how do you pass arraylists as arguments to another class, and how does the method/class accept this arraylist for use
how to pass variable from simple java main class(not servlet) to the jsp page?
how to pass variable from simple java main class(not servlet) to the jsp page?  I have a simple Java class in which I invoke a call to a JSP page... from the simple Java class to the JSP page. How can I do that? Here is my
Class
and Perimeter of the square and another class is rectangle which is using for getting... that how to to implement the constructor feature in a class. This program is using two classes. First class is another and second is the main class which
pass a variable(friends name) through a hyperlink in to another jsp.
pass a variable(friends name) through a hyperlink in to another jsp.  ... in to the next page,but i want to pass a specific friend name which i was clicked,plz tell me how i do this? thanks
pass a variable(friends name) through a hyperlink in to another jsp.
pass a variable(friends name) through a hyperlink in to another jsp.  ... page,but i want to pass a specific friend name which i was clicked,plz tell me how i do this? thanks
Use varibles from another class
Use varibles from another class  **I have two classes. class 1:** public class askfigures extends JFrame { method from class1: public void... in another class. another class: public class Askvalues extends JFrame
How To Pass data from one GUI to another in java swing
How To Pass data from one GUI to another in java swing  I'm new... data input. I'm stuck at how to get the user's input from JTextFields and combobox...*; import java.awt.GridLayout; public class RetailCalculatorProject extends JFrame
How can i pass the valus from a JSP to the action class???
How can i pass the valus from a JSP to the action class???  hewllo wevryone... can anyone help me with how i can pass the value of menuId in my JSP and pass it in the action class
how to set the class path variable in tomcat ?
how to set the class path variable in tomcat ?  description... for the useBean class attribute action.TestBean is invalid...;jsp:useBean id="test" class="action.TestBean" /> <jsp:setProperty name
you pass a variable by value.
you pass a variable by value.  How do you pass a variable by value... $a = &$b /*--------------Pass By value----------------*/ function add($a) { return ++$a; } add($a); /*---------------Pass by reference
Example of a class variable (static variable)
Example of a class variable (static variable)   ... you can define the static class variable in a class. When a number of objects... of a class variable. It will be updated each time the instance has been called. We
How to call the run method from another class?
How to call the run method from another class?  Sorry, if this is a stupid question. I would like to find out how to call the run method... run() { new FereastraPrincipala().setVisible(true); from the class
class
class  can any body give me idea how to write code for Country.java is a class to represent a country in medal tally. It has an attribute of country... medals. In this class, you should also define constructors, and assessor, mutator
Private variable of class
Private variable of class  Hi..... What keyword allows you to refer to private variables of a class in flex? Please give me an example for that Thanks  Ans: private keyword and this keyword
How to pass Array of string from action class to jsp page
How to pass Array of string from action class to jsp page  this is my action class package login.ipm; import java.sql.*; import java.util.ArrayList... class DiagservicesAction extends org.apache.struts.action.Action { private static
How do you pass a variable by value?
How do you pass a variable by value?  How do you pass a variable by value
How to pass javascript variable in Scriplet of JSP?
How to pass javascript variable in Scriplet of JSP?  How can I assign the value of a javascript variable to a variable declared in jsp scriplet? Is it possible
get the value from another class - Java Beginners
get the value from another class  Hello to all, I have stupid...().trim(); [/code] How I can get String alsl = ((Node)flnameTEXT.item(0... javax.xml.transform.stream.StreamResult; public class xmlRead{ static public void main(String[] arg
Java call method from another class
Java call method from another class       In this section, you will study how to access  methods of another class. For this we have created two java files
What is a local, member and a class variable?
What is a local, member and a class variable?   Hi, What is a local, member and a class variable? thanks
class and Object
class and Object  how many classes,References and objects...(); There are 2 classes, Class A and Class B. References : 1 (Object of B is referenced by A) Variable: a Thanks
Class and Instance
Class and Instance  class IdentifyMyParts { public static int x=7; public int y=3;} What are the class variable? What are the instance variables... a method. There is only one copy per class, regardless of how many objects
Assigning a value to JSP variable from a bean class. - JSP-Servlet
Assigning a value to JSP variable from a bean class.  Hi, I want to know how we can assign value to a JSP variable from a Java Bean. I am using Struts, JSTL. Which tags should I use to assign the value. e.g Kindly
Pass by Reference - Java Beginners
variable to a method. Example: public class PassByRefernce{ public static...Pass by Reference  Hi Friends, What is Pass by value and Pass by Reference?can u please explain with examples.is java supports Pass by reference
how to pass string array from action class to jsp page? pls reply me.
how to pass string array from action class to jsp page? pls reply me.  how to pass string array from action class to jsp page? pls reply me.  .... In your action class, String[] arr = {"A","B","C","D"}; for (int x = 0; x < arr
Static variable in java
methods, variable inside a class and static class. Static variable is also called class variable which belongs to class not to object. Static variable is declared inside a class but outside the method or Constructor
Difference between the local and class variable.
Description: The class variable are declared in the class but not within methods of any class. Whereas the local variable exits within the methods of any... between the class and local variable. Showing Local Variable
how to pass arraylist data from one jsp to another jsp - JSP-Servlet
how to pass arraylist data from one jsp to another jsp  hi to all iam not able to pass the data which is stroed in arraylist, actually i need... the following >XXX/ ? is required to send a value from one jsp to another
How to pass value of a link to a textfield
How to pass value of a link to a textfield  Dear Sir, in my project I'm initially making a value of the textfield as a link. Now, I want to pass...").value=s; } </script> <a href="#" class="leftlinks" onclick="fun('Hello
Is there a data structure like a class that doesn't need to be defined as a class in it's own file?
Is there a data structure like a class that doesn't need to be defined as a class in it's own file?  I am new to java, and I am trying to make... ArrayLists easier. For example, I want to create the class Equipment which
java pass by reference
java pass by reference  i understood java always pass arguments by pass by value so that the original value does not change...... but i want to know how we change the value and make it effect the original value by passing
How to access sub class member using super class object
How to access sub class member using super class object  class A{ } class B extends A{ int b=1; } class Test{ public static void main(String args[]) { what to do here to access sub class variable b using super class object
how can we pass parameters from jsp href to another servlet
how can we pass parameters from jsp href to another servlet  how can we pass parameters from jsp href to another servlet
Get JTextField value from another class
Get JTextField value from another class       In this section, you will learn how to get the textfield value from other class. For this, we have created two classes ClassA.java
PHP Variable variables
PHP Variables variable: Variables variable is a new kind of technique of using variables, in this technique we need to use more than one variable and we can... the use of variable variable both in general use as well as in OOP concept. PHP
Java nested class example
Java nested class example  Give me any example of Nested Class.   Nested Class: Class defined within another class is called nested class... Class"; //NestedClass instance variable InnerClass innerClass = new
JAVA CLASS INHERITANCE
JAVA CLASS INHERITANCE  Someone please help me write this program. Create a class called Accounts that has the following members: i)An instance integer variable called acc_no. ii) An instance string variable called acc_name. ii
how to pass an array from one jsp to another jsp - JSP-Servlet
how to pass an array from one jsp to another jsp  hi friedns, can any One tell me how to send an array from one jsp to another jsp,pls any one send the code for this.also porvid the code how to retrive the arry in another jsp
Class
class. Now we will learn, how to define a class having methods, objects... Class       This section explores the concept of a class in reference to object oriented programming
Variable Names
Java Notes Variable Names Basic variable naming conventions Choosing good names is probably... easy to choose an unhelpful name. Later, or to another reader, it's often obvious
store data from a variable in mysql?
me how to retrieve data from a database mysql and store it in an int variable... of the calculation from an int variable into mysql in a new table of database. how... is then saved to another table. import java.sql.*; class RetrieveData { public static
How to pass value from dijit.Tree to dijit.MenuItem - Ajax
How to pass value from dijit.Tree to dijit.MenuItem  Hi Friends, I... side(Struts action class) I have passed a JSON structure through URL... with the menu. But I want to pass the value of an item to its menu item
How to define variable in Velocity
How to define variable in Velocity       This Example shows you how to define a variable... of VelocityContext Class. 3:-Create Template class object, Template class object
[JSP] How to pass back ID to previous page.
[JSP] How to pass back ID to previous page.  Hi experts, May I ask something. How to link a page to previous page which the content in previous page is selected from database where IDPRODUCT=". I don't know how to pass back
inner class
inner class  what is mean by inner class   Inner class is a non-static class which is defined inside another class
class
class  Is a class a subclass of itself
Local Variable and Instant Variable
Local Variable and Instant Variable  difference between Local Variable and Instant Variable   Difference between local variable and instance variable Instance variable is declared within a class but not within

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.