[Java] Classes, constructors, static members

Chapter 9 Class Mechanism

I was a little confused by the method call in FQCN and the instance (attribute, operation) from the class, so I organized it first.

// FQCN: Fully Qualified Class Name

class

Instance fields are attribute variables.

Instances are created from fields and operations (methods, actions) defined in the class.

has-a relationship: A relationship in which one class uses another class as a field.

What is a constructor?

A method that is automatically executed immediately after the class is new. public class Hero { int hp; Hero() { this.hp = 100; // Initialize the hp field with 100. } }

"Call another constructor" rule in overload

Class(String names) { this.name = names; this.hp = 100 Class { this("Bob"); }}

Static field

If you add static to the field, it becomes a static field. Accessing a static field from an instance variable also affects the original static field.

Recommended Posts

[Java] Classes, constructors, static members
Java static
Java static story
Instance concept, class type variables, constructors, static members
java classes, instances, objects
Java static [Personal summary]
[Java] Superclass / subclass constructors
java (classes and instances)
[Java] Stack area and static area
(Note) Java classes / variables / methods
[Java] Generics classes and generics methods
[Java] JavaConfig with Static InnerClass
[java] Reasons to use static
About abstract classes in java
Benefits of Java static method
Java abstract methods and classes
[Java] Various summaries attached to the heads of classes and members
About Java static and non-static methods
I compared PHP and Java constructors
Java, abstract classes starting from beginners
List of members added in Java 9
Java generics (defines classes and methods)
How to use classes in Java?
Classes and instances Java for beginners
[Read Effective Java] Chapter 2 Item 1 "Consider static factory methods instead of constructors"