[Class](https://ja.wikipedia.org/wiki/%E3%82%AF%E3%83%A9%E3%82%B9_(%E3%82%B3%E3%83%B3%E3% 83% 94% E3% 83% A5% E3% 83% BC% E3% 82% BF)) is a blueprint, and based on this blueprint, [instance](https://ja.wikipedia.org/ Generate wiki /% E3% 82% A4% E3% 83% B3% E3% 82% B9% E3% 82% BF% E3% 83% B3% E3% 82% B9).
It's a good idea, so let's explain it also as an object-oriented explanation. [Object Oriented](https://ja.wikipedia.org/wiki/%E3%82%AA%E3%83%96%E3%82%B8%E3%82%A7%E3%82%AF%E3% 83% 88% E6% 8C% 87% E5% 90% 91)
It's endless if you give detailed explanations, so in the spirit of "get used to it rather than learn" First, let's "practice".
Let's open Ideone in a browser. You should see the following automatically, and the class definition for Ideone should be included by default.
class
class Ideone{
〜
}
The part of corresponds to "class". Declaring a class named Ideone. For the time being, enter the class part as shown below Let's press the green button "Run" at the bottom right.
python
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Ideone.Person tarou = (new Ideone()).new Person("Tarou");
tarou.walk(12);
Ideone.Person hanako = (new Ideone()).new Person("Hanako");
hanako.walk(3);
}
class Person
{
private String name;
Person(String name){
this.name = name;
}
public void walk(int dist){
System.out.println(this.name + " walked for about " + dist + " kilometers.");
}
}
}
You can also try forking this.
I will show an example to fix the memory.
1.〜
~ So far today
Recommended Posts