This is a Java object-oriented memo for new employee training.
It is a concept of componentization, and was conceived to overcome "complexity that humans cannot grasp".
//①
public class Car{
String maker
int displacement
String color
void start(){
System.out.println("Start")
}
void turn(){
System.out.println("Bend")
}
void stop(){
System.out.println("Stop")
}
}
//②
public class TestCar{
public static void main(String[] args) {
Car car = new Car();
}
}
What you are doing object-oriented. (Example above) ① Create a car design document ↓ (2) Manufacture an instance (new) car based on the car design document.
The constructor is executed immediately after instantiation. Only the first.
//Basic format of constructor
public class class name
name of the class() {
//The automatic execution process is described here.
}
}
The constructor has the same method name and class name. No return value in method declaration (no void) Variables declared in a class block are called fields.
private Can only be accessed from the same class
Class is private The method is public Fields are qualified with private.
The field is hidden by private and accessed via getter and setter methods. The method protects the field.
//Getter method formula
public The type of field to retrieve the value get field name() {
return this.Field name;
}
To be able to call the fields of your class from other classes A method that just returns the contents of the field
//The standard of the setter method
public void set field name(Field type Arbitrary variable name) {
this.Field name=Arbitrary variable name;
}
A method that simply assigns a specified value to a specific field
Overriding means overriding the members of the parent class on the child class side when declaring a child class that inherits the parent class.
Inheritance indicates that two classes have a specialization / generalization relationship. Inheritance source, superclass Inherit to subclass
Think of an instance vaguely.
relationship of is-a Child class is-a Parent class (child class is a kind of parent class)
Java's virtual world is a computer memory area
The object-oriented programming I learned in Java training is being put to good use in my current work. This article was compiled by me as a programming beginner, so if you have any advice, I would be very grateful if you could comment!
Outside of work, I use Ruby and Ruby on Rails to create portfolios. I will continue to do my best in the future.
Recommended Posts