how to pass class variable to another class

Ads
 

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 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

Ads









Related Tutorials/Questions & Answers:
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
Advertisements
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
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
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
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
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
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
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 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
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
how to set class path
how to set class path  how to set class path in java
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
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
How to create a class in java
How to create a class in java  I am a beginner in programming and tried to learn how to do programming in Java. Friends please explain how can I create a class in Java
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 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 to make paging with class and ajax
how to make paging with class and ajax  paging with class and ajax
how send nsnotification to forward class
how send nsnotification to forward class   how to send nsnotification to a forward class? i am sending a nsnotification to a class which is not loaded yet. example,there is a class A,where i am creating a dictionary and posting
How to Declare Abstract Class in PHP ?
How to Declare Abstract Class in PHP ?  hi, I am a PHP Beginners. As i am trying to make an application where i trying to declare the abstract class of PHP. Please any one explain me how to declare abstract class in PHP program
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 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 to make paging with class and ajax
how to make paging with class and ajax  paging with class and ajax   imran.php <?php class pagination{ var $row... displayLinks($show){ $this->show = $show; // How many links to show
Use of Local Inner class
Use of Local Inner class       The Java language enables you to define a class inside another class. Such a class is defined as Nested Class or Local Inner class. The Nested
In Java how to get size of class and object?
In Java how to get size of class and object?  In Java how to get size of class and object
In Java how to get size of class and object?
In Java how to get size of class and object?  In Java how to get size of class and object

Ads