Register Login
Internet / AI Technology University (ITU/AITU)





|

Top Links: Technology - Discussion >> Internet Technology Summit Program - Discussion >> 1. Java Introduction - Discussion
Current Topic: 1.2.2.Java Style - Discussion
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? Highlight the text in question Or


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:

catColor=black


We invite you to create your own questions and answers (QnA) to increase your rank and win the Top Creativity Prize!

Topic Graph | Check Your Progress | Propose QnA | Have a question or comments for open discussion?

Have a suggestion? - shoot an email
Looking for something special? - Talk to AI
Read: IT of the future: AI and Semantic Cloud Architecture | Fixing Education
Do you want to move from theory to practice and become a magician? Learn and work with us at Internet Technology University (ITU) - JavaSchool.com.

Technology that we offer and How this works: English | Spanish | Russian | French

Internet Technology University | JavaSchool.com | Copyrights © Since 1997 | All Rights Reserved
Patents: US10956676, US7032006, US7774751, US7966093, US8051026, US8863234
Including conversational semantic decision support systems (CSDS) and bringing us closer to The message from 2040
Privacy Policy