java-array-object-exception

It feels good...

Array

Declaration: dataType[] array;
For example: int[] num;

int[] nums;
nums = new int[10];

Java uses the new operator to create an array

Get the length of the array:

array.length

Array is also an object, and the elements in the array are equivalent to the member variables of the object

Object

A static method can be called in another class in the same package, call the method
class name. method name ();
non-static methods need to instantiate the class.
For example, if you want to call the say method in the Student class,
instantiate

Student student = new Student();
student.say();

Insert picture description here
Constructor
Even if a class does not write anything, there will be a method, which is a constructor method, also called a
constructor. The characteristics of a constructor:
1. Must be the same as the name of the class
2. There must be no return value, and void
function cannot be written . :
1. To use the new constructor, there must be a constructor
2. It is used to initialize the value

Once there is a parameterized construct, there must be a non-parameter
Insert picture description here
alt+insert automatically generated constructor

Inheritance
JAVA only has single inheritance and not multiple inheritance

Use the keyword extends to indicate
for example:

public class Student extends Person

super:
1. To call the constructor of the parent class, it must be the first of the subclass method
2. Super must only appear in the method or construction method of the
subclass 3. Super and this cannot call the constructor at the same time

this: call this object itself, you can use
super without inheritance : the application representing the parent class object can only be used under inheritance conditions

Rewrite : there needs to be an inheritance relationship, the method of subclass rewriting the parent class
1. The method name must be the same
2. The parameter list must be the same
3. The range of modifiers can be expanded or not reduced public>protected>default>private
4. Throwing The scope can be reduced but not expanded

Abstract class:
1. This abstract class cannot be new, but can only be realized by subclasses
2. Common methods can be written
in abstract classes 3. Abstract methods must be in abstract classes

Interface:
The keyword for declaring the interface is interface
that all the definitions in the interface are abstract, and all are public abstract.
Interfaces need to have implementation classes. Use implements
for example:

public class User implements UserService

The methods in the interface must be rewritten

abnormal

Five keywords for exception handling:
try, catch, finally, throw, throws

Guess you like

Origin blog.csdn.net/AlienEowynWan/article/details/115033278