Q:
Java find output programs (static Keyword) | set 1
belongs to collection: Java find output programs
Java find output programs
- Java find output programs (Data Types) | set 1
- Java find output programs (Data Types) | set 2
- Java find output programs (Data Types) | set 3
- Java find output programs (Operators) | set 1
- Java find output programs (Operators) | set 2
- Java find output programs (Operators) | set 3
- Java find output programs (if else) | set 1
- Java find output programs (if else) | set 3
- Java find output programs (switch case) | set 1
- Java find output programs (switch case) | set 2
- Java find output programs (switch case) | set 3
- Java find output programs (Loops) | set 1
- Java find output programs (Loops) | set 2
- Java find output programs (Loops) | set 3
- Java find output programs (Arrays) | set 1
- Java find output programs (Arrays) | set 2
- Java find output programs (Arrays) | set 3
- Java find output programs (this Keyword) | set 1
- Java find output programs (final Keyword) | set 1
- Java find output programs (final Keyword) | set 2
- Java find output programs (static Keyword) | set 1
- Java find output programs (static Keyword) | set 2
- Java find output programs (Parameter Passing) | set 1
- Java find output programs (Class and Objects) | set 1
- Java find output programs (Class and Objects) | set 2
- Java find output programs (Class and Objects) | set 3
- Java find output programs (Constructor & Destructor) | set 1
- Java find output programs (Constructor & Destructor) | set 2
- Java find output programs (Constructor & Destructor) | set 3
- Java find output programs (Inheritance) | set 1
- Java find output programs (Inheritance) | set 2
- Java find output programs (Inheritance) | set 3
- Java find output programs (Interface) | set 1
- Java find output programs (Interface) | set 2
- Java find output programs (Interface) | set 3
- Java find output programs (Overloading) | set 1
- Java find output programs (Overloading) | set 2
- Java find output programs (Overriding) | set 1
- Java find output programs (Overriding) | set 2
- Java find output programs (Overriding) | set 3
- Java find output programs (Exception Handling) | set 1
- Java find output programs (Exception Handling) | set 2
- Java find output programs (Exception Handling) | set 3
- Java find output programs (Enumeration) | set 1
- Java find output programs (Enumeration) | set 2
- Java find output programs (Autoboxing & Unboxing) | set 1
- Java find output programs (Autoboxing & Unboxing) | set 2
- Find output programs (Java String class)
- Find Output of Java program - 1 (Mixed topics)
- Find Output of Java program - 2 (Mixed topics)
- Java find output programs (if else) | set 2
Answer Question 1:
Output:
Explanation:
The above program will generate syntax errors because we cannot access static methods using "::" operator. Here, we need to use '.' operator to access static methods.
The correct way to call the static method is given below:
Sample.staticFun();
Answer Question 2:
Output:
Explanation:
The above program will generate syntax errors because here we accessed non-static data members X and Y from static method staticFun(). We cannot access non-static members from static members of the class.
Answer Question 3:
Output:
Explanation:
The above program will generate syntax errors because here we declared constructor of Sample class as a private, and we created the object of the Sample class in main() method of StaticEx class and we know that we cannot access private members outside the class.
Answer Question 4:
Output:
Explanation:
In the above program, we created a Sample class that contains a static data member count and a no-argument constructor and a static method ObjectCount().
Here, we increased the value of static variable count in the constructor that will count the total created objects. The ObjectCount() method is used to print the total number of objects created.
Answer Question 5:
Output:
Explanation:
In the above program, we created a Sample class that contains a static data member count and a no-argument constructor and a static method ObjectCount().
Here, we increased the value of static variable count in the constructor that will count the total created objects. The ObjectCount() method is used to print the total number of objects created.
Now look to the main() method, here we created three objects of Sample class and call ObjectCount() method with each object then "3" will be printed each time.
need an explanation for this answer? contact us directly to get an explanation for this answer