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



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

Have Programming Question? Ask it here!
 
 
 


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


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
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
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
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
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
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
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 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
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 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 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
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
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
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
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
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 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
Pass value of rasio button from jsp page to action class(not conventional problem)
Pass value of rasio button from jsp page to action class(not conventional... button) to be deleted On clicking 'delete' button . Hence I need to pass eventId... in action class using getter setter and hence corresponding data can be deleted. i
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
How do you call a constructor for a parent class?
How do you call a constructor for a parent class?  How do you call a constructor for a parent class
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
How do I decompile Java class files?
How do I decompile Java class files?  How do I decompile Java class files
Super class of an Exception class
Super class of an Exception class  hello,,, What is super class of an Exception class?   hii,, the super class of an exception is throwable class. and the super class of an throwable class is the object class
Advertisements
 

 

 

DMCA.com