Q:
Java find output programs (Constructor & Destructor) | set 3
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 of the below statements,
Object O1 = new Student(); Object O2 = new Student(102,"Rohit",5000); (Student)(O1).printInfo(); (Student)(O2).printInfo();
In the above code we did not typecast objects properly. The correct way is given below,
Student S1 = (Student)O1; Student S2 = (Student)O2; S1.printInfo(); S2.printInfo();
Answer Question 2:
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 an object array of Student class and initialized with the parameterized constructor and then we print student detail on the console screen.
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 an object array of Student class and called no-argument constructor with object S[0] and called parameterized constructor with object S[1]. Then finally called the printInfo() method to print student details on the console screen.
Answer Question 4:
Output:
Explanation:
The above program will generate syntax errors because of the below method,
The above method looks like a destructor in C++, but java does not support destructors in Java.
Answer Question 5:
Output:
Explanation:
The above program generates syntax error because we used the final keyword with a parameterized constructor. The final keyword is not allowed with constructors in Java.
need an explanation for this answer? contact us directly to get an explanation for this answer