public class SimpleClass { private int id; private String name; public SimpleCla
ID: 3596560 • Letter: P
Question
public class SimpleClass {
private int id;
private String name;
public SimpleClass() {
name = “”;
id = 0;
}
public void setName(String name) {
this.name = name;
}
}
THE FOLLOWING 3 QUESTIONS REFER TO THE CODE FRAGMENT ABOVE –
BASE YOUR ANSWERS ON WHAT YOU SEE – DON’T ASSUME ANYTHING!
1. SimpleClass cannot be executed as a standalone program/process :
(a) TRUE
(b) FALSE
Explain: ___________________________________________
2. Given the implementation of SimpleClass above, which of the following
attempts to create an instance of it would compile successfully? (pick one):
(a) SimpleClass simple = “CSI”;
(b) SimpleClass simpleClass = new SimpleClass(“CSI”);
(c) SimpleClass simple = SimpleClass();
(d) SimpleClass simpleClass = new SimpleClass();
3. Did the implementer of SimpleClass consider encapsulation when
designing/coding this “simple class”?
(a) Yes!
(b) No!
Explain: ______________________________________________________
_____________________________________________________________
Explanation / Answer
1.
(b) FALSE
SimpleClass can be executed as a stand-alone program. It doesn't require any web service dependencies to execute the program.
2.
(d) SimpleClass simpleClass = new SimpleClass();
3.
(a) Yes!
The above class is encapsulated. It is combination of constructor, variables and functions which is said to be encapsulation.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.