public class UpperCaseString { //1 protected String content; // 2 public UpperCa
ID: 3596569 • Letter: P
Question
public class UpperCaseString { //1
protected String content; // 2
public UpperCaseString(String s) { // 3
content = s.toUpperCase(); // 4
} // 5
public String toString() { // 6
return content.toUpperCase(); // 7
} // 8
public static void main(String[] args) { // 9
UpperCaseString us =
new UpperCaseString("Easy Midterm!"); // 10
System.out.println(us); // 11
} // 12
} // 13
THE FOLLOWING 4 QUESTIONS REFER TO THE CODE FRAGMENT ABOVE
7. When UpperCaseString is executed/run, what gets displayed to the console?
__________________________________________________
8. FYI, the core Java “java.lang.String” Class is defined as follows:
public final class String extends Object
implements Serializable, …
{
…
}
Could the UpperCaseString Class have been implemented by extending
String, rather than have it use an instance of String (as a data member)?
Yes!
No!
Explain: _____________________________________________________
______________________________________________________________
4
9. Review line 11 above. What UpperCaseString method is implicitly being invoked
in order to display a value to the Console?
______________________________________________________________
10. Review line 2 above. Assuming every detail was deliberate, what might the
developer have been thinking when he/she decided to specify protected
access?
______________________________________________________________
Explanation / Answer
Please find my anser.
Q7. Ans: EASY MIDTERM!
Q8. No, because FINAL classes can not extended. String class is FINAL class.
Q9. toString() method is called implicitly
Q10. protected members are available for child (subclasses), so developer might be thing that some one will extend their class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.