in Education by
What is the static variable?

1 Answer

0 votes
by
What is the static variable? The static variable is used to refer to the common property of all objects (that is not unique for each object), e.g., The company name of employees, college name of students, etc. Static variable gets memory only once in the class area at the time of class loading. Using a static variable makes your program more memory efficient (it saves memory). Static variable belongs to the class rather than the object. //Program of static variable class Student8{ int rollno; String name; static String college ="ITS"; Student8(int r,String n){ rollno = r; name = n; } void display (){System.out.println(rollno+" "+name+" "+college);} public static void main(String args[]){ Student8 s1 = new Student8(111,"Karan"); Student8 s2 = new Student8(222,"Aryan"); s1.display(); s2.display(); } } Test it Now Output:111 Karan ITS 222 Aryan ITS Static Variable

Related questions

0 votes
    I have some ASP.NET web services which all share a common helper class they only need to instantiate one ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 31, 2022 in Education by JackTerrance
0 votes
    I have some ASP.NET web services which all share a common helper class they only need to instantiate one ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 30, 2022 in Education by JackTerrance
0 votes
    I have some ASP.NET web services which all share a common helper class they only need to instantiate one ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 29, 2022 in Education by JackTerrance
0 votes
    I have some ASP.NET web services which all share a common helper class they only need to instantiate one ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 29, 2022 in Education by JackTerrance
0 votes
    I'm having some trouble recently. On a WebForm I declare a static object, like this : public static ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    I'm having some trouble recently. On a WebForm I declare a static object, like this : public static ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    I'm having some trouble recently. On a WebForm I declare a static object, like this : public static ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    Here is the code class method { int counter = 0; public static void main(String[] args) { System.out. ... variables of the class? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    Here is the code class method { int counter = 0; public static void main(String[] args) { System.out. ... ),Core Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    What is a static variable?...
asked Jan 17, 2021 in Technology by JackTerrance
+1 vote
    What is a static variable in C-Programming?...
asked Nov 9, 2020 in Technology by JackTerrance
0 votes
    Private static IP addresses can be assigned to a/an __________. A. VM B. Load Balancers C. Application Gateway D. All the options...
asked Nov 20, 2022 in Education by JackTerrance
0 votes
    In case of stochastic update, can static equilibrium be reached? (a) yes (b) no This question was addressed ... Neural Networks of Neural Networks Please answer the above question....
asked Aug 27, 2022 in Education by JackTerrance
0 votes
    Can Invariances be build as static functions in the structure? (a) yes (b) no The question was asked during ... of ANN of Neural Networks Please answer the above question....
asked Aug 26, 2022 in Education by JackTerrance
0 votes
    My S3 bucket hosts a static website. I do not have cloudfront set up. I recently updated the files ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
...