hoge.java
class Car //car
{
private int num; //member//field(State / nature)
private double gas; //member//field(State / nature)
public Car() //Constructor 1
{
num = 0;
gas = 0.0;
System.out.println("I made a car.");
}
public Car(int n,double g) //Constructor 2//Overload
{
num = n;
gas = g;
System.out.println("number" + num + "Gasoline amount" + gas + "Created a car.");
}
public void show() //member//Method
{
System.out.println("The car number is" + num + "is.");
System.out.println("The amount of gasoline" + gas + "is.");
}
}
class Hoge
{
public static void main(String[] args)
{
Car car1 = new Car(); //object(mono)
car1.show();
}
}
What is the object to create? This time it's a car.
Things created from the class. An image in which a class is defined and an object is created from it.
A representation of the nature of the object. If it's a car, it's gasoline, colors ...
When tied to an object, it is called a instance variable.
If you set it to static, you can access it without declaring the object.
This is called a class variable.
The process of changing or referencing the created object. Set the amount of gasoline and set the color.
When tied to an object, it is called a instance method.
If you set it to static, you can access it without declaring the object.
This is called a class method.
You can refer to it with Car.show () without creating an object.
A generic term for fields and methods.
When set to public, members can be accessed from outside the class.
If set to private, it will not be possible to access members from outside the class.
When you declare a class that has the same function as the class name Constructor processing is performed. The constructor is not a member.
Declare duplicate constructor or method names.
The number of arguments must be changed.
Also called diversity, it seems to be one of the important functions of Java.
Refer to the members of the created object.
Recommended Posts