This article is a memorandum. Although it is a reference book level content, the code posted in this article is about ** Wrong ** are the main things. This is for the purpose of posting the part that was actually mistaken during coding and posting it for self-reflection. In addition, I will not touch on the deep part here because I will review it later while also studying the Java Silver exam questions.
This time, I will not deal with mistakes. The story of the class is important in Java, and I haven't understood it enough to make a mistake. Please forgive me for reconfirming the definition in the correct form.
Language: Java11, JDK13.0.2 Operating environment: Windows 10
Hello,world!.java
class helloWorld
{
public static void main(String[] args)
{
System.out.println("Hello,world!");
}
}
This is the simplest program, which produces Hello, world!
Output in Java. As you can see in the first line, this time the theme is ** class (class
) **. It is a function that is always handled when handling Java.
According to the reference book "Easy Java 7th Edition"
What is a class? A concept used to create a program while summarizing the state and nature of things and the functions related to them.
Is. My current understanding is that class
is the recognition of preparing a reference sample, so to speak, a template before dealing with specific individual objects.
Cat.java
class Cat
{
String name;
double weight;
double size;
String color;
int ID;
String voice;
//There is no end to the list! !!
}
I let this class declare a small part of the status of a "general cat". However, this does not include the characteristics of "my cat".
Let's actually create a mycat
with" my cat "status while processing the main method.
myCat.java
class myCat
{
public static void main(String[] args)
{
Cat mycat = new Cat();
//Create an object of Cat class in mycat variable
mycat.name = "Tet";
mycat.color = "brown";
mycat.ID = 3;
System.out.println("My cat's name is" + mycat.name + "。");
System.out.println("color is" + mycat.color + "、" + mycat.ID + "The second cat.");
}
}
//Output result: My cat, my name is Tet.
//The color is brown, the third cat.
A ** object ** or ** instance ** is defined in class Cat
and created in mycat byCat mycat = new Cat ();
.
In my next plan, I will deal with a program that outputs Hello, World!
, Which is written first by anyone who touches the program. I thought that I should write it first, but as a person who entered from Python
, Hello, World
of Java
had to use a class from the beginning and it was very difficult, so I waited so far.
In the next installment, we will deal with the ** fields ** and ** methods ** that we have omitted this time. This time, the content was thin, but I'm not so confident about the future, so I'll divide it as an index of my current ability.
I write variables and expressions as much as possible and compile them, so if I want to quote them completely, I will describe that.
Easy Java 7th Edition Java SE11 Silver Problem Collection (commonly known as Kuromoto)
Recommended Posts