Memorandum of new graduate SES [Java object-oriented edition]

[Java Object Oriented]

This is a Java object-oriented memo for new employee training.

Object-oriented (property, method)

It is a concept of componentization, and was conceived to overcome "complexity that humans cannot grasp". image.png

//①
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.

[Three major object-oriented functions]

① Encapsulation (access control)

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 and setter

//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

② Inheritance ([extends] create something similar)

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

③ Diversity (almost the same. The result is efficient development)

Think of an instance vaguely.

relationship of is-a Child class is-a Parent class (child class is a kind of parent class)

① ② ③ Use these to reproduce the virtual world in your computer

Java's virtual world is a computer memory area

Chat

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

Memorandum of new graduate SES [Java object-oriented edition]
Memorandum of new graduate SES [Java basics]
Experience of passing Java Silver as a new graduate
Java 3 major elements (object-oriented) memorandum
Summary of object-oriented programming using Java
Java memorandum
JAVA memorandum
Introduction of New Generation Java Programming Guide (Java 10)
[Java] Object-oriented
Introduction of New Generation Java Programming Guide (Java 11)
Introduction of New Generation Java Programming Guide (Java 12)
Introduction of the new generation Java programming guide (Java language extension project "Amber" edition)
Japanese Advent Calendar Java Edition of Synthetic Sequences
Ubuntu18.04 LTS minecraft server java edition construction memorandum
I touched on the new features of Java 15
Object-oriented FizzBuzz (Java)
[Java] Object-oriented summary_Part 1
[Java] Object-oriented syntax-Constructor
Object-oriented (Java) basics
java1.8 new features
[Java] Object-oriented summary_Part 2
Java study memorandum
[Java] Overview of Java
[Java] Optional memorandum
[Java] Object-oriented syntax-Package
Summary of revisions (new era) support by Java version
Career theory that new graduate engineers of humanities think
[Java] When writing the source ... A memorandum of understanding ①