Q:
Java find output programs (Constructor & Destructor) | set 2
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:
In the above program, we created a class Student that contains data member sid, name, and fees. Here, we defined a default constructor and a parameterized constructor to initialize the data members with specified values, and we also defined a printInfo() method to print the values of data members.
The default constructor initialized data member with 101, "virat", and 8000 respectively.
In the parameterized constructor we tried initialized data members but we used local parameters with the same name that's why here data members were not initialized because sid, name, and fees are local variables not data members inside the parameterized constructor.
Answer Question 2:
Output:
Explanation:
The above program will generate syntax error because the setInfo() method of the Student class does not have a return type.
Answer Question 3:
Output:
Explanation:
In the above program, we created a class Student that contains data member sid, name, and fees. Here, we defined default and parameterized constructor to initialize the data members, and we also defined setInfo() and printInfo() method to set and print the values of data members.
Now look to the CtorEx class, the CtorEx class contains the main() method, which is the entry program of the program. Here, we created objects S1 and S2. Object S1 initialized using the default constructor and S2 initialized using the parameterized constructor.
Student S3 = new Student();
We set values of S3 object using the setInfo() method and then print the student details using the printInfo() method on the console screen.
Answer Question 4:
Output:
Explanation:
In the above program, we created a class Student that contains data member sid, name, and fees. Here, we defined default and parameterized constructor to initialize the data members, and we also defined setInfo() and printInfo() method to set and print the values of data members.
Now look to the CtorEx class, the CtorEx class contains the main() method, which is the entry program of the program. Here, we created objects S1 and S2. Object S1 initialized using the default constructor and S2 initialized using the parameterized constructor.
Here, we assigned the reference of an S1 object to the S3, then S1 and S3 will point the same object. Then we set the values of S3 object using the setInfo() method, these new values will be reflected in both S1 and S3.
Then print the student detail for all objects using the printInfo() method on the console screen.
Answer Question 5:
Output:
Explanation:
In the above program, we created a class Student that contains data member sid, name, and fees. Here, we defined default and parameterized constructor to initialize the data members, and we also defined setInfo() and printInfo() method to set and print the values of data members.
Now look to the CtorEx class, the CtorEx class contains the main() method, which is the entry program of the program. Here, we created two anonymous objects and call the printInfo() method that will print student details on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer