Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


raja
how to pass class variable to another class
1 Answer(s)      4 years and a month 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.


Advertisement
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 Tutorials/Questions & Answers:
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
Advertisements
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
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
how to use string of one class into another Class
how to use string of one class into another Class  I created textField(JTextField t1=new JTextField();(it is in ClassA. The input of this textField i.e t1.getText() is to be used in different(another Class say in ClassB. How can
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 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
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
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
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 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
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
how to value of one variable pass in other variable in revetse order
how to value of one variable pass in other variable in revetse order  Like variable a=367 b must have valuev763
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
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
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 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
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
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
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
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
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
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
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
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
class
class  Is a class a subclass of itself
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
how to set class path
how to set class path  how to set class path in java
Advertisements
 

 

 

DMCA.com