Home Answers Viewqa Java-Beginners making consistency of data member in the whole programme without using static keyword

 
 


vivek
making consistency of data member in the whole programme without using static keyword
0 Answer(s)      8 months ago
Posted in : Java Beginners

In the below programme i use one boolean variable named check , which is being accessed inside main function by two objects of Tst1 and Test2 . But the value of check variable is not maintained in the programme . we can use static but i want to know some alternative way ..could anyone give me some hints on it ? Thanks in advance .

Inside jointdeatils.h

#pragma once

class Jointdetails
{
public:
    Jointdetails(void);
    ~Jointdetails(void);
    bool check;


};

Inside jointdeatils.cpp

#include "Jointdetails.h"

Jointdetails::Jointdetails(void)
{
    check = false ;
}

Jointdetails::~Jointdetails(void)
{
}

Inside analyzer.h

#pragma once
#include "Jointdetails.h"
class Analyzer
{
public:
    Analyzer(void);
    Jointdetails* GetJointDetails();
    Jointdetails* m_ptheCTJointDetails;
    ~Analyzer(void);
};

Inside analyzer.cpp

#include "Analyzer.h"
#include "stddef.h"
Analyzer::Analyzer(void)
{
    m_ptheCTJointDetails = new Jointdetails();

}

Analyzer::~Analyzer(void)
{
}
Jointdetails* Analyzer::GetJointDetails()
{

    if(m_ptheCTJointDetails) 
        return m_ptheCTJointDetails;
    else
        return NULL;


}

Inside Test1.h

#pragma once
#include "Analyzer.h"
class Tst1
{
public:
    Tst1(void);
    Analyzer *analyzer1 ;
public:
    ~Tst1(void);
};

Inside Test1.cpp

#include "Tst1.h"

Tst1::Tst1(void)
{
    analyzer1 = new Analyzer ;
}

Tst1::~Tst1(void)
{
}

Inside Test2.h

#pragma once
#include "Analyzer.h"
class Test2
{
public:
    Test2(void);
    Analyzer *analyzer2 ;
public:
    ~Test2(void);
};

Inside Test2.cpp

#include "Test2.h"

Test2::Test2(void)
{
    analyzer2 = new Analyzer ;
}

Test2::~Test2(void)
{
}

Inside main.cpp

#include "Test2.h"
#include "Tst1.h"
#include "stdio.h"

int main()
{
    Tst1 *test1 = new Tst1 ; //check = false
    Test2 *test2 = new Test2 ; //check = false
    test1->analyzer1->GetJointDetails()->check = true ;
    if(test2->analyzer2->GetJointDetails()->check )
        printf("Check value is changed");
    else
        printf("Check value is not changed");
        return 0 ;
}
View Answers









Related Pages:
making consistency of data member in the whole programme without using static keyword
making consistency of data member in the whole programme without using static keyword  In the below programme i use one boolean variable named check... . But the value of check variable is not maintained in the programme . we can
static
is applied to member variables, it means that the static variable is shared among all instances of the class. When static is applied to methods, the static keyword...static  what r the main uses of static in java   Hi Friend
Static keyword in public static void main
: static keyword indicates that this method can be invoked simply by using the name... is declared by using static keyword. Following is an example of static declaration...Static keyword in public static void main  Hi, I have seen
static keyword
static keyword  please give some detail about Static keyword.   Static Variables Static variables are class variables that are shared... method can access only static data. It can not access non-static data (instance
why using static keyword
why using static keyword  why using static keyword
Access Static Member Of The Class Through Object
Access Static Member Of The Class Through Object  ... that work without any object of the class. Static methods are limited to calling other static methods in the class and to using only static variables
programme
programme  Using an ATM, customer can access their bank accounts... programme to implement a simple ATM for 15 customers. Initially you have to store... using array(s). Then the program ask user to input account number and password
PHP Static Variable and Methods
the method using class, without instantiating any object. Example of PHP Static... should use static methods and variables. Static keyword is used to make only one... of that attribute. Static data are used when some data has to share within
Static Variable
of a class, an object, is created. When static is applied to member variables.... When static is applied to methods, the static keyword means that the specified...Static Variable  What is the basic use of introducing static variable
Member Classes
. Member classes can also use instances of the same class without explicit delegation. Only the member classes can be declared as static. Local... Member Classes      
static Java Keyword
static Java Keyword       The static is a keyword defined in the java programming language. Keywords... in java programming language likewise the static keyword indicates the following
Static variable in java
. Static variable is accessed without creating object of class using class name...Static variable in java. Static is a keyword in java used to create static...; Classname.variablename; Example: Using Static Variable. public class Staticvariable
static keyword
static keyword  Hii, In which portion of memory static variables stored in java. Is it take memory at compile time? thanks deepak mishra
static keyword with real example
static keyword with real example  static keyword with real examplestrong text
Super - keyword
Super - keyword       super keyword super is a keyword in java that plays an important role in case of inheritance. Super keyword is used to access the members of the super class. Java
avoid using the whole URL
avoid using the whole URL  How can I avoid using the whole URL
applet images sleeping programme - Applet
implements Runnable { Thread thread = null; final static int width = 400; final static int height = 300; Image image; Graphics graphics; // bouncing lines member variables int[] x1; int[] y1; int
static keyword in interface
static keyword in interface  Could any one explain,why static keyword implict (or explict ) come in interface? I asked lot of persons about this question, but nobody did not answered clearly. please explain clearly and say what
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
static
,then use static blocks and without creation of object we need to perform some task,then go for static methods. If we want variables those values will not be changed...Static Concept  in what are all the situation we may use static
Making Exceptions Unchecked - java tutorial,java tutorials
of can put into try block to monitor for exception. Using catch, you can handle.... For throwing exception explicitly, we use keyword throw. Any known exception... checked exceptions are thrown using throws clause. try and catch example
Member Classes, Inner Nested Classes in java
explicit delegation. The member class is the only class that we can declare static... is declared. If we want to remove this restriction, we declare the member class a static... Member Classes      
SQL as Keyword
SQL as Keyword      ... keywords like, create table keyword is used to create a table Stu_Table with field attribute and data type respectively. The insert into add a records
Making Enumerations Iterable - JDK 5 Example
UnsupportedOperationException(); } }; } } Second Way The second way for using it is by making... { public static void main(String[] args) { Vector<String> sv = new...;Francis"); sv.addElement("Kabutz"); // using the generics makes
call to a member function
call to a member function  While uploading the data on server i am getting following error... call to a member function children
The final Keyword
The final Keyword       The final is a keyword. This is similar to const keyword in other languages. This keyword may not be used as identifiers i.e. you cannot declare
Without Using Form in Java Script
Without Using Form in Java Script  HOw to Reset the data in javascript without using form tag
without scanner
without scanner  a company need a system to store the data about... attributes : name , age , salary and note that we need to solve it using array... the program will read the data through console or not? Please clarify this! Thanks
Retriving data from MYSQL without line break using java
Retriving data from MYSQL without line break using java  get data without line breaking from mysql table (i.e data stored as mediumtext )using java
Sorting arraylist without using Collection.sort()
Sorting arraylist without using Collection.sort()  Hi, How can I sort an arraylist without using Collection.sort() nad also I am not allowed to use any other data structure in the program? Is there any algorithm by using which I
programme - Java Beginners
programme  java programme to implement stack operation?use stack to check whether a given string is polidrome or not  Hi Friend, Please... class CheckPalindrome{ public static void main(String[] args) { String
lucky no programme - Java Beginners
lucky no programme   Sir , with due respect , iam a beginner level programmer i need some hint in making lucky no programmme . So please send me lucky no programmme on my mail
Java static method example
Description: Static variable are used within the static method. Non static variable do not exits in the static method. Static variables are shared by its class instances. Static variable can be used without using the instances
Java programme - Java Beginners
Java programme  Develop a multi-threaded GUI application using java application
JAVA programme - JDBC
static void main(String[]args){ Scanner input=new Scanner(System.in
how to retrieve data from database using combobox value without using request.getParameter in jsp - JSP-Servlet
how to retrieve data from database using combobox value without using request.getParameter in jsp  Answer pl
Nonaccess Member Modifiers - Java Beginners
Nonaccess Member Modifiers  what is Nonaccess Member Modifiers give... (abstract, final, native, static, strictfp, synchronized, transient, volatile) can... and/or static. ------------------------------------------- Visit for more
The interface keyword
variable i.e. the variables defined as final and static. One benefit of using... The interface keyword       In java programming language the keyword interface in java is used
JAVA programme - Java Interview Questions
for such class is encouraged.Following is expected from the programme: a.Use of 3... in the main function and using correct logic
demonstrate a) static data members b) static methods
demonstrate a) static data members b) static methods  demonstrate a) static data members b) static methods
Double To Int Without TypeCasting
Double To Int Without TypeCasting  How to convert Double to Int without using typecasting?   class ConvertDoubleToInt { public static void main(String[] args) { double d=25.5; int num=new
The double Keyword
The double Keyword       The double is a Java keyword that may not be used as identifiers i.e. you...-precision floating-point number. It is also a java primitive data type
Breaking a string into words without using StringTokenizer
Breaking a string into words without using StringTokenizer  how can we Break a string into words without using StringTokenizer ??   ... { public static void main(String[] args) { Scanner input=new
Static Nested Classes
class having keyword static in the outer class. class OuterClass... Static Nested Classes       A nested class that is declared static is called a static nested class
DataGrid without DataBase
DataGrid without DataBase  I want display list of data without using... have to display the content of these elements but without having... MBA above you can see, it can show like this. The Data of manish and aman
String length without using length() method in java
String length without using length() method in java  How to count length of string without using length() method in java?   Here is Example... the number of character into the given string without using the length() method
transient keyword
transient keyword  how to use transient keyword?   Hi Friend, The transient keyword is used to indicate that the member variable should not be serialized when the class instance containing that transient variable
The float Keyword
The float Keyword         The float is a Java keyword that may not be used as identifiers i.e.... single-precision floating-point number. It is also a java primitive data type
The import keyword
The import keyword      ... in the package without specifying the package name to which the class belongs. Syntax: Here... compile easily finds the corresponding source file simply by using fully qualified
Example of static method
methods. Static methods can't use any instance variables. The this keyword can't... and static method.  A static method can be accessed without creating... Example of static method      

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.