My second class,teacher xiong brief introduced some concepts about class and objects.It seems to be easier to understand what class and
objects are,but when you further comprehend those things you would find something unexpected always appear to frustrate you.
1.What constract one class?
(1)attribute and atrribute programming
for example
//set the class' attributes
//for the precious programming you should set the private attribute
private String name;
private int blood;
//create the attribute grammars
public void setName(String n){
name=n;
}
public String getName(){
return name;
}
public void setBlood(int n){
blood=n;
}
public int getBlood(){
return blood;
}
(2)class methods(object action)
for example:
public void attack(ManagerHU a){
int b=a.getBlood()-1;
a.setBlood(b);
System.out.println(a.getName()+"is being attacked and" +a.getName()+"'s blood is"+b);
}
TIPS:
Why we define the private attribute?
A:One thing should always be kept in mind that class is imitating the reality things in the world.Everything has its own attribute and no one can easily change it.In order to contribute a harmony promgramming world we have to do this.
We create diffrent class depending on its own attributes and actions.So we have one formwork to create one which has just been listed above.
Q:Can we regard the class we creates as a data type?
A:Abusolutely we can.Take the String for example,so we can easily understand it.
Here is my Manager code
public class Manager {
/**
* the entrance of the Procedure
*/
public static void main(String[] args){
//crate the object
Baron b=new Baron();
ManagerHU m=new ManagerHU();
//set the objects' attribute
b.setName("LichKing");
b.setBlood(5);
m.setBlood(6);
m.setName("MountKing");
//now the PK begin
while(b.getBlood()!=0&&m.getBlood()!=0){
b.attack(m);
m.attack(b);
}
if(b.getBlood()==0){
System.out.println(m.getName()+" win");
}
}
}
key words:attribute method
OK, so much for the class and object.Without them a vivid virtual world can't be created under our keyboard(or by coding).
分享到:
相关推荐
Static data members are common to all objects of a class, and their value is not unique per object. Static member functions, also known as class methods, can be called without creating an instance of...
Class图Object图和包 uml基础可以看看
C++程序设计教学课件:Chapter 3 class and object 本节课程主要介绍C++程序设计中的类和对象,涵盖了面向对象编程、类和对象的定义、构造函数和析构函数、组合、静态成员、常量对象和常量成员函数等关键概念。 一...
### LDAP提示Object Class Violation详解 #### 一、问题背景 在LDAP(Lightweight Directory Access Protocol,轻量目录访问协议)的使用过程中,有时会遇到一个常见的错误提示:“object class violation”。这一...
【解惑】类与对象的初始化问题 - 爪哇人
最简单的代码阐述最深刻的原理。JavaScript所谓的类/对象,是模拟的,因为javascript本身不是面向对象的。本文件(含有注释)精简的介绍了javascript类的属性、方法(包挂静态属性和方法)的应用,还有构造函数的...
chapter6_class_object.ipynb
python爬虫案例pb08_class_object.rar
Systems Analysis and Design: An Object-Oriented Approach with UML, 5th Edition by Dennis, Wixom, and Tegarden captures the dynamic aspects of the field by keeping students focused on doing SAD while ...
Python中的Class和Object是面向对象编程的基本组成部分,它们在创建可复用的代码结构和实现模块化编程中扮演着重要角色。本文将详细介绍这两个概念及其相关的用法。 **类(Class)** 类是一种抽象的数据类型,它...
"Kotlin基础教程之dataclass,objectclass,use函数,类扩展,socket" Kotlin是一种现代化的静态类型语言,运行于Java虚拟机(JVM)上,并且是Java的替代语言。Kotlin提供了许多特性来简化编程,使开发者更容易编写高...
ComboBox Extending the ComboBox Class and Its Items.检查
the full 3D shape and pose of all object instances in the image. Our method produces a compact 3D representation of the scene, which can be readily used for applications like autonomous driving. Many ...
在Python编程语言中,"class"与"object"是面向对象编程(OOP)的核心概念。面向对象编程是一种编程范式,它将程序设计为由各种独立的对象组成,每个对象都有其特定的功能和数据。接下来,我们将深入探讨这两个概念。...
existing superpixel classication framework for semantic scene segmenta- tion and achieve a 24% relative improvement over current state-of-the-art for the object categories that we study.We believe ...
Vcl.SuperObject 是 Delphi 开发环境中一个用于处理 JSON 数据的库,其核心类为 SuperObject_class。这个库提供了一种高效且灵活的方式来创建、解析和操作 JSON 对象。在 Delphi 中,SuperObject 使得与 JSON 格式的...
Class Persistence Object (CPO) 是一个用于对象到 JDBC 映射 (OJM) 的 Java api 和实用程序。 与 ORM 技术和 java 持久性 api 不同,CPO 旨在允许您充分利用数据库的本机 sql 和功能。
Object Oriented Analysis and Design 12Singleton - MotivationA Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance. This is beneficial ...
"Unity导入Excel文件自动创建class文件和ScriptObject文件,并转化成ScriptObject的插件pro版"就是为了解决这一问题而设计的专业工具。 首先,让我们深入理解这个插件的核心功能。它允许开发者直接在Unity编辑器中...