Q:
Java find output programs (Class and Objects) | 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 error because we did not create an object of the Sample class correctly.
The correct way to create an object of Sample class is given below:
Sample S = new Sample()
In Java, we need to use the new operator to create an object of the class.
Answer Question 2:
Output:
Explanation:
In the above program, we created a class Sample that contains two data members var1 and var2 without any access modifier. If we did not specify the access modifier then it will be treated as default, it means these data members can be accessed within the same package.
In the Sample class, we defined a method set() to set the values of data members of the Sample class.
In the main() method we created object S of Sample class and then call set() method to set values to the data members and then print the values of data members on the console screen.
Answer Question 3:
Output:
Explanation:
The above program will generate a compile-time error because we did not create an object of the Sample class correctly.
Here, we created object S in C++ fashion but we cannot create an object like this in Java.
The correct way to create an object is given below:
Sample S = new Sample();
Answer Question 4:
Output:
Explanation:
The above program will generate a compile-time error because we can create only one public class that contains the main() method in Java.
Answer Question 5:
Output:
Explanation:
In the above program, we created a class Sample that contains two data members var1 and var2 initialized with 20 and 40 respectively.
In the main() method, we created object S of Sample class and then print the values of data members on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer