Write a class StaticDemo consists of ‘ a’ and ‘b’ static integer variables (a= 42 and b = 32) and static method find() - which displays ‘b’ value. Create a class StaticByName to call the method and access the static variable ‘a’ to display the values of a and b

0

Assignment: Module 03- Part 01

Write a class StaticDemo consists of ‘ a’ and ‘b’ static integer variables  (a= 42 and b = 32) and static method  find() - which displays ‘b’ value. Create a class StaticByName to call the method and access the static variable ‘a’ to display the values of a and b
Java Fundamentals Module 03 - Part 01

02. Write a class StaticDemo consists of ‘ a’ and ‘b’ static integer variables  (a= 42 and b = 32) and static method  find() - which displays ‘b’ value. Create a class StaticByName to call the method and access the static variable ‘a’ to display the values of a and b

Input: static int a  = 42; static int b = 32;

output:  a= 42 b = 32

class StaticDemo {
    static int a = 42;
    static int b = 32;

    static void find() {
        System.out.println("b = " + b);
    }
} 
And here's an example implementation of the StaticByName class that calls the find() method and accesses the a variable:
class StaticByName {
    public static void main(String[] args) {
        StaticDemo.find();
        System.out.println("a = " + StaticDemo.a);
    }
} 
In this example, when the main method of StaticByName class is called, it will display the value of variable b using find() method and variable a using classname. variable.
For example, if you run the StaticByName class, the output would be:
b = 32
a = 42  

👉Write a class CallByValue to accept two integers from user and swap the values – use call by value.👈

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
✨ Updates