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 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 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..._TO_REPLACE_1 Try the following code: import java.util.*; class A { static int regd
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
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
Use varibles from another class
Use varibles from another class  **I have two classes. class 1... in another class. (adsbygoogle = window.adsbygoogle || []).push({}); another class: public class Askvalues extends JFrame { in the method
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
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 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
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 do you pass a variable by value?
How do you pass a variable by value?  How do you pass a variable by value
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 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
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
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
class
class  Is a class a subclass of itself
Class
and Perimeter of the square and another class is rectangle which is using for getting.... First class is another and second is the main class which name is Construct... Area of rectangle : 6 Value of x in another class : 3 Area
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
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
how to set class path
how to set class path  how to set class path in java
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
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
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 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
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
how to make paging with class and ajax
how to make paging with class and ajax  paging with class and ajax
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 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
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
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
inner class
inner class  what is mean by inner class   Inner class is a non-static class which is defined inside another class
Java Nested Class
Java Nested Class         In Java programming language, when a class is defined within another class then such a class is called a nested class. Nested classes are a feature
Super class of an Exception class
Super class of an Exception class  hello,,, What is super class of an Exception class?   hii,,ADS_TO_REPLACE_1 the super class of an exception is throwable class. and the super class of an throwable class
How many ways we can pass the variable through the navigation between the pages?
How many ways we can pass the variable through the navigation between the pages?  How many ways we can pass the variable through the navigation between the pages
class and Object
class and Object  how many classes,References and objects... In the statement: A a=new B(); There are 2 classes, Class A and Class B. References : 1 (Object of B is referenced by A) Variable: a ThanksADS_TO_REPLACE_2
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
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
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
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
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
onclick pass variable - JSP-Servlet
onclick pass variable  on button onclick event pass variable and print in textbox in same page... i want to pass value of variable at onclick event of button and also want to print it in textbox in same page....  Hi
Nested class
Nested class  What is nested class?  when a class is defined within another class then such a class is called a nested class. Nested... readable and maintainable code. class OuterClass { ... static class
.class and .tld
.class and .tld  how to create .class and .tld file

Ads