[Java Bronze] Learning memo (interface, static method, type conversion, etc.)

A summary of common mistakes when learning Java Bronze.

interface

-Fields are constants only </ b> All fields are implicitly qualified with final static </ b>. (Modifiers can be omitted) Fields can be qualified with static (* Because the value defined by static can be executed without creating an instance)

-All methods are implicitly qualified with public abstract </ b> </ b> You cannot qualify a method with static. (* Static methods cannot be modified because they can be executed without creating an instance.)

static method

You cannot access the instance field defined in your class from the static method. </ b> → A compilation error has occurred!

Static methods can be executed without creating an instance. A compile error occurs to prevent the instance field from being accessed from the static method before creating the instance.

Downcast

Assigning an instance of a parent class to a child class type. Forcible type conversion is possible by using the cast operator.

No compilation error occurs. However!

The moment you actually try to assign, an exception occurs (ClassCastException) </ b>

Upcast

Assigning an instance of a child class to the type of a parent class.

Executing a method that is in the parent class but not in the child class will result in a compilation error </ b>.

Signature

-Method name -Number of arguments -Argument type -Argument order

That

Initial value of variable

Variables are initialized with a default value when they are created.

・ Byte type 0 ・ Short type 0 ・ Int type 0 ・ Long type 0L ・ Float type 0.0f ・ Double type 0.0d ・ Char type'\ u0000' ・ Boolean type false -Reference type null

Recommended Posts