JAVA from 6 to 7 pleases 6. Printing objects. Consider the class below: public s
ID: 3720441 • Letter: J
Question
JAVA
from 6 to 7 pleases
6. Printing objects. Consider the class below: public static void main (String[] args) Employee e1- new Employee("John", "Jones", 80000); System.out.println(e1); When the main method above runs, the output produced is: Employee@bac49a What printed above? Which method is printing this? What should we do to get the information about the Employee to print? Does every class have to have a toString) method? Can we print the instance variables of the class in a method called, printObject, instead?Explanation / Answer
Ques 6.
(a)
The toSting() method is printing this. toString() is the method in the Object class and is called when we try to print the class onject. We can override the toString() function in any class. So, in our class, the toString() function prints the information about the class.
(b) If we have overridden the toString() method, we just have to pass the object in
System.out.print();
(c)
No, it is not mandatory to override the toString() method.
(d)
Yes, we can define a method to print the details about the class.
Ques 7.
(a) Answer : 2
It is because if there is always a default constructor in the class. If we don't define it explicitly, the Java compiler does it for us. Also, there is a parametarized constructor. SO, it make 2 constructor.
(b) ANswer : 3
The methods are:
(c) Answer : 3
The methods are:
(d) An integer variable which represents the id of the student which we want to remove.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.