You have a privilege to create a quiz (QnA) related to this subject and obtain creativity score...
1. What are we trying to derive at writing the program class Cat
we try to describe cat properties that we think we need in our software application
usually we do this based on requirements to the application
2.
private String color;
What is the minimum or maximum Data we could have
- no limit
3.
What other kinds of Data do we have
that is what else can I use to replace
private String color;
private String weight; ???
--- better
private double weight;
4
What is the minimum or maximum number of methods we can have before the main method?
-- no limit - it is matter of requirements
5
Must main methods be the last?
--- no, but it is a good style
6
Please explain this methods
public void setColor(String color) {
this.color = color;
}
public String getColor() {
return color;
}
Do we always have set and get in methods before the main? - yes, this is a good style
Why is the first one public void
What exactly are we doing here public void setColor(String color) // we assign a variable, we return nothing - that means void
What is happening here this.color = color; can you give me another sample
Was it clear so far?
public void setColor(String colorVariable) {
color = colorVariable; // the names are different, so we do not need to use THIS
}
What exactly are we doing here public String getColor() {
What is happening here return color;
--when we call this method:
String myColor = myCat.getColor(); // the method returns the value of internal variable color and assign this value to external variable, in that case String myColor
7
is this always how to write the main method
public static void main(String[] args) {
-- yes, the main method has pre-defined signature and we must use it that way
8
Cat myCat = new Cat();
Class object = constructor is this illustration right
are we making an object of the class by saying Cat myCat = new Cat();
-- yes, read comments
9
is this how to set the color of the constructor
myCat.setColor("black"); // we set the variable color to "black" - by using the method setColor - not by using a constructor
10
What happened here
String catColor = myCat.getColor(); // we get color variable value from the internal class data and assign to a string catColor
System.out.println("catColor="+catColor); // so we can display (print) this value
Not sure of how we got value of +catColor
-- plus in strings means concatenation - addition to the text, so the result is: