Q:
Java find output programs (Constructor & Destructor) | 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 a compile-time error because in the above program we defined a no-argument constructor with a private modifier that cannot be accessed outside the class but we created the object of Student class in the main() method of CtorEx class.
Answer Question 2:
Output:
Explanation:
In the above program, we created two classes Student and CtorEx. The Student class contains three data members sid, name, and fees. we also created no-argument constructor and printInfo() method. The constructor is used to initialize the data members with some default values and printInfo() is used to print the values of data members on the console screen.
Now look to the CtorEx class: The CtorEx class contains the main() method, the main() method is the entry point of the program. Here we created the object S of Student class and then called the printInfo() method to print student information on the console screen.
Answer Question 3:
Output:
Explanation:
The above program will generate a syntax error because of the below statement,
Student S1 = new Student();
In the above statement, we call no argument constructor but we did not define a no-argument constructor in the Student class.
Answer Question 4:
Output:
Explanation:
In the above program, we created a class Student that contains data member sid, name, and fees initialized with 101, "Virat", and 8000 respectively. Here, we defined a default constructor with an empty body 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.
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 objects S1 and S2. The object S1 calls no-argument constructor and S2 calls parameterized constructor, and then call printInfo() method with both object to print student detail on the console screen.
Answer Question 5:
Output:
Explanation:
The above program will generate a compile-time error because of the definition of the no-argument constructor.
Student(): sid(101),name("Virat"),fees(8000) {}
Here, we tried to initialize data members using member initializer list, C++ supports member initializer list to initialize data members but java does not support member initializer list.
need an explanation for this answer? contact us directly to get an explanation for this answer