Home Answers Viewqa Java-Beginners redeclare static variable in the inherited class

 
 


Anitha
redeclare static variable in the inherited class
0 Answer(s)      a year and 2 months ago
Posted in : Java Beginners

can we redeclare static variable in the inherited class like this:

public class StaticClass1 {

 class StaticClass1{

    static int noOfInstances;

    StaticClass1(){

        noOfInstances++;

    }

}

 class StaticClass extends StaticClass1

{   public static void main(String[] args){

        StaticClass1 sv1 = new StaticClass1();

        System.out.println("No. of instances for sv1 : " + sv1.noOfInstances);

        StaticClass1 sv2 = new StaticClass1();

        System.out.println("No. of instances for sv1 : "  + sv1.noOfInstances);

        System.out.println("No. of instances for st2 : "  + sv2.noOfInstances);

        StaticClass1 sv3 = new StaticClass1();

        System.out.println("No. of instances for sv1 : "  + sv1.noOfInstances);

        System.out.println("No. of instances for sv2 : "  + sv2.noOfInstances);

        System.out.println("No. of instances for sv3 : "  + sv3.noOfInstances);

                **//here i have redeclared the static variable as "25" is it possible,then what is static variable**

                noOfInstances=25;


        StaticClass1 sv4 = new StaticClass1();

        System.out.println("No. of instances for sv1 : "  + sv1.noOfInstances);

        System.out.println("No. of instances for sv2 : "  + sv2.noOfInstances);

        System.out.println("No. of instances for sv3 : "  + sv3.noOfInstances);

        System.out.println("No. of instances for sv4 : "  + sv4.noOfInstances);

        StaticClass1 sv5 = new StaticClass1();

        System.out.println("No. of instances for sv1 : "  + sv1.noOfInstances);
        System.out.println("No. of instances for sv2 : "  + sv2.noOfInstances);
        System.out.println("No. of instances for sv3 : "  + sv3.noOfInstances);
        System.out.println("No. of instances for sv3 : "  + sv4.noOfInstances);
        System.out.println("No. of instances for sv3 : "  + sv5.noOfInstances);
    }

}


//}
View Answers









Related Pages:
static
redeclare static variable in the inherited class  can we redeclare static variable in the inherited class like this: public class StaticClass1 { class StaticClass1{ static int noOfInstances; StaticClass1
Static Variable
of a class, an object, is created. When static is applied to member variables, it means that the static variable is shared among all instances of the class...Static Variable  What is the basic use of introducing static variable
static
, The Static means that a certain object/variable is resident in memory and accessed each time an instance of a class, an object, is created. When static is applied to member variables, it means that the static variable is shared among all
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.... Static variable is accessed without creating object of class using class name
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 static variable first of all create a class StaticVariable. Define one static
PHP Static Variable and Methods
copy of the variable for the class. All objects of that class will access one copy... the all objects of that class. If we declare a method as static then we can access the method using class, without instantiating any object. Example of PHP Static
non static variable cannot be referenced from static context
non static variable cannot be referenced from static context  public class Add{ int foo=7; int bar=8; public int add(int x,int y... "non static variable cannot be referenced from static context". How to solve
non static variable cannot be referenced from static context
non static variable cannot be referenced from static context  public class Add{ int foo=7; int bar=8; public int add(int x,int y... public static void main(String []s){ Add a1=new Add(); a1.add(7,8
Variable Names
. Class - Static variables are sometimes prefixed... Java Notes Variable Names Basic variable naming conventions Choosing good names is probably
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
static
static  What is the exact need of declaring a variable as static?   A static variable is a variable who's single copy in memory is shared by all objects,so any modifications to the static variable will modify it's value
STATIC
is an example: public class StaticTest { static{ System.out.println("Hello from...STATIC  WHAT IS STATIC BLOCK?EXPLAIN , AND WHAT IS THE DIFFERENCE BETWEEN STATIC BLOCK AND STATIC METHOD?   A STATIC block is automatically
static variable in php
static variable in php  How can i call a global variable as a static variable
static
instance of that object (the object that is declared static) in the class... of the class that is initialized. Another thing about static objects is that you...Static Concept  in what are all the situation we may use static
static functions
)It is a variable which belongs to the class and not to object(instance). 2)Static...)A single copy to be shared by all instances of the class. 4)A static variable can... variables. 3)A single copy to be shared by all instances of the class. 4)A static
how to inherit static variable
how to inherit static variable   how to inherit static variable or methods in Java?? Please explain the entire process of inheriting the variable. Thanks in advance
STATIC VARIABLE DECLARATION
STATIC VARIABLE DECLARATION  why cannot the static variable declare inside the method
What is the importance of static variable?
What is the importance of static variable?  hi, What is the importance of static variable? thanks
static keyword
instances of the class. 4)A static variable can be accessed directly by the class name...; Static Variables Static variables are class variables that are shared by all instance of class .. 1)It is a variable which belongs to the class
Serialize the static variable
Serialize the static variable  hello, Can we serialize the static variable?   hii Yes we can serialize the static variable. if u don't want to serialize, u need to declare the variable as transient
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
Static keyword in public static void main
; The variable declared with static keyword is called class variable. This variable is shared by all the instances of the class. The static variable can be accessed...: static int i=10; The variable declared with static keyword is called class variable
static object array
static object array  static object array   Dynamically call a static variable array class Blog { public static $template = array('content' => 'doodle'); } Blog::$template['content'] = 'bubble'; $class = 'Blog
static & instance - Java Beginners
static & instance  what is different between static variable and instance variable .? plz explain with example. and when we can use static variable and when can use instance variable.    public class Main
Example of a instance variable
class,  the same copy of  instance variable is provided to all... we have used in the constructor of a class. We can't call the non-static variable in a main method. If we try to call the non-static method in the main
About Static Class
About Static Class  is it neccessary to create object for static class
Can a class be declared as static?
Can a class be declared as static?  Hi, Can a class be declared as static? thanks
class static - Java Beginners
class static  When do we declare a member of a class static?  Hi friend, public class HowToAccessStaticMethod{ int i; static int j; public static void staticMethod(){ System.out.println("you can access
Can we declare a static variable inside a method?
Can we declare a static variable inside a method?   Hi, Can we declare a static variable inside a method? thanks
Static final variables - Java Beginners
Static final variables  can a static final variable be accessed by a instance (non-static)method?  Hi, static final variable u can access in non-static method. but the variable should has accessibility, means
Declare Reference variable
in memory when object is created. Static variable is class variable which... variable static int b; // static variable A ref; static... of object creation, but here i am declaring reference variable in class
Store Variable in Java
Store Variable in Java  How to store Variables in Java?   public class DoubleTest { public static void main(String[] args) { double...(aDouble); // Outputs 7.21 } }   Variable in Java
about static import - Java Beginners
*; class B { public static void main(String ar[]) { System.out.println(i... is not static. Use public modifier instead of protected modifier in Class...: package mypack; public class TestA { public static int i=100; } 2
static Java Keyword
:   -- The static keyword is applicable to an inner class (a class..., a static keyword is used with a class (inner) needed to be instantiated, even... static keyword with a class: public class Class1
Example of static method
an instance of the class. If you try to use a non-static method and variable defined in this class then the compiler will say that non-static variable or method... variable and other is class variable. Make one static method named staticMethod
Static
an instance of a class. Static methods are implicitly final method, since overriding depends on the type of the object, and static methods are attached to a class... Static       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 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
Using Abstract Class
class. This class must be inherited. Unlike interface the abstract class may... but we can call its static method by its class name. The code...Using Abstract Class      
Static database class - JSP-Servlet
Static database class  I want to create a static database class and i want to use that class in all servlets ? How can i achive
Initializing Integer Variable issue?
Initializing Integer Variable issue?  My program is supposed to take... on how to shorten/optimize the code are welcome. Code below. public class Chapter5Problem5 { public static void main(String[] args) { String inputPhrase
Local Variable and Instant Variable
Local Variable and Instant Variable  difference between Local Variable and Instant Variable   Difference between local variable and instance variable Instance variable is declared within a class but not within
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
Static/Class methods
). Qualifying a static call From outside the defining class, an instance method... will be used. Example Here is a typical static method. class MyUtils... class. If called from outside the class and it wasn't declared static, it would
What is the difference between a static and a non-static inner class?
What is the difference between a static and a non-static inner class?   Hi, What is the difference between a static and a non-static inner class? Thanks
Local Variable ,Package & import
Variable public class LocalVar { public static void main(String args... the Class Variable public class ClassVar { private static int... it is declared. Example of Local variable : The class variable are declared in the class
store data from a variable in mysql?
is then saved to another table. import java.sql.*; class RetrieveData { public static...store data from a variable in mysql?  sir last time asked you tell me how to retrieve data from a database mysql and store it in an int variable
Get Environment Variable Java
of the System class and gets the information about environment variable. get... Get Environment Variable Java       In this example we are getting environment variable. To get
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
Static Nested Classes
; A nested class that is declared static is called a static nested class... independently of any particular outer class object. A static nested class use... an object reference. A static nested class interacts with the instance

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.