Java Basics/Lesson sixth: Classes and objects in object-oriented/Java

Source: Internet
Author: User

2018-03-06

Process-oriented and object-oriented

1. Process-oriented programming: Starting with each step of solving a problem, it is appropriate to solve a relatively small simple problem. program = algorithm + data.

2. Object-oriented programming: according to the characteristics of the real world to manage complex things, to abstract them into an object, with their own state and behavior, through the response of the message to complete a certain task.

Program = object + message.

Two, object-oriented three major features:

1. Encapsulation: Hides its information properties and methods, providing only the interface that invokes the method, both encapsulated.

2. Inheritance: The properties and methods in an existing class are preserved and can be combined with their own unique properties and methods to form a new class that inherits.

3. Polymorphism: Refers to the same name, but there are different implementations of the multiple methods exist in a program. There are two ways to do this: overloading and overwriting.

A class is a description of a group of similar things that have the same properties, operations, and relationships, and is abstract, conceptually defined.

An object is an instance (instance) that actually exists for each individual of that kind of thing.

Iii. definition of class:

A class primarily defines the properties (variables), methods, and relationships of a class.

A class is composed of a class declaration and a class body; Format:

//class declaration Public classHero {//class BodyString name;//name    floathp//Blood Volume    floatArmor// Armor    intMovespeed;//Moving Speed  Public Static voidMain (string[] args) {Hero Garen=NewHero (); Garen.name= "Galen"; GAREN.HP= 616.28f; Garen.armor= 27.536f; Garen.movespeed= 350; Hero Teemo=NewHero (); Teemo.name= "Tim Mo"; TEEMO.HP=383f; Teemo.armor=14f; Teemo.movespeed= 330; }  }

Class is like a template, according to such a template, you can create a specific hero
A specific hero, called the object
New Hero () is the meaning of creating a Hero object in Java

Iv. declaration of the object:

Instantiation and initialization of objects

person P1 = new Person ("Tom", 0);

Name of the class: person

Name of object: P1

The New keyword instantiates an already declared object and allocates memory space in the heap;

When an object is created, the member variables of each of these types are automatically initialized for assignment.

Variable types other than the base data type are reference types, such as the person above and the previously mentioned array.

Java Basics/Lesson sixth: Classes and objects in object-oriented/Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.