Newcomer training using the Web-Basic programming / classes using Java-

Newcomer training using the Web-Basic programming using Java-

class

[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".

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.

java01.png

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.

Commentary

I will show an example to fix the memory.

example

1.〜


~ So far today

Recommended Posts

Newcomer training using the Web-Basic programming / classes using Java-
Newcomer training using the Web-Basic programming using Java-
Java comparison using the compareTo () method
Summary of object-oriented programming using Java
Try using the Stream API in Java
Java Programming Style Guide for the Java 11 Era
Java programming (classes and instances, main methods)
Try using the Wii remote with Java
About the idea of anonymous classes in Java
ChatWork4j for using the ChatWork API in Java
The story of learning Java in the first programming
Try accessing the dataset from Java using JZOS
Display "Hello World" in the browser using Java
Display "Hello World" in the browser using Java
Try using the COTOHA API parsing in Java
Java development training
java programming basics
java Generic Programming
Output the maximum value from the array using Java standard output
[Java] Sort the list using streams and lambda expressions
Try implementing the Eratosthenes sieve using the Java standard library
Java classes and instances to understand in the figure
Using the database (SQL Server 2014) from a Java program 2018/01/04
Try global hooking in Java using the JNativeHook library
Differences in code when using the length system in Java