Home > Back-end >  Java classes and objects
Java classes and objects

Time:03-03

The concept of object and class

Class: class is a template, it describes the behavior of the class of objects and status,

Object: the object is an instance of a class, have state and behavior, for example, a dog is an object, its state are: color, names, variety; Behavior: wagged his tail, called, eat, etc.,

Borrow the figure on the net easy to understand the classes and objects, the boys and girls in the picture below for the class, and the concrete are each object:



Class:

Define the class of the basic format:



Modifier for public final abstract or don't write

A,
the constructor
Constructor is called a constructor or constructor, the constructor is the same as the name of the class, not return a value, even can't write void;

The constructor definition format:



Name the same as the name of the class, there is no return value, can't write void

If there are no added manually in a class constructor, the compiler will add one more a no-parameter constructor by default

If you manually add a constructor (regardless of the form), the default constructor will disappear

The constructor can be overloaded

Construct highly loaded [each constructor must have a unique parameter types list] :



2, the member variable

Member variables: variables defined in the class, method body outside of the variables, these variables when creating objects instantiated, member variables can be in a class method, construction method and the specific class block access,



Modifier (public protected private) three choose one, the static and final

Three, the method

Java method is the set of statements, they together to perform a function,

Orderly combination method is the steps to solve the problem of a

Methods included in the class or object

Methods in the program is created, referenced elsewhere



Modifier (public protected private) three choose one, the static, final, the synchronize, native

CodePudding user response:

The first great

CodePudding user response:

CodePudding user response:

Speak simple
  • Related