`
HeyGirl
  • 浏览: 6169 次
  • 性别: Icon_minigender_2
最近访客 更多访客>>
社区版块
存档分类
最新评论

Class and object

阅读更多

I am sorry to delay writing the summary.

 

Q1:what is object?

A1:Object must be an concret.For example,girl can refer to a wide range,but this girl named xuying is an concret.Also,we often describe an object in two aspects:characteristic and action.For example,the girl's name,age is her characteristics and studying is her action.

  We all know the world comprises numerous objects,and these objects can be divided into many classes according to their similarities.

 

Q2:What is class?

A2:Class is a template.Its contents are based on the real objects.Class contains objects' attributes and fuctions.Attributes refer to characteristics and fuctions refer to actions.We can add the objects' attributes and fuctions into the class,so when we use class to new an object,it will be convenient to call the object's functions and assign its attributes.

 

Q3:Can object act as a parameter to be delivered?

A3:Of course it can.The class we define is also a data type,so the class can be the type of parameter and the object can be a parameter.

 

Here are some codes.

//This is a  class of Character.
 //name of parameters
 private String name;
 private int blood;

 

Q4:Why use private to set all member variables' access right in the class,not public?

A4:For the sake of safety.Private makes member variables can be used only in its own class,other classes can't use them,even in its extend class.For example,you have a name attribute,if public,everyone can change your name,if private,only you can change it,which one do you prefer?

 

//设置角色的名字属性
 public void setName(String n){
  name = n;
 }
 //获得角色的名字属性
 public String getName(){
  return name;
 }

 

The funcions above are different,one has parameter and the other doesn't.



 

 

 

 

 


Next lesson we study the class and object further.

 

Q5:What's the difference between common method and construction method?

A5:1、the name of construction method must be the same with the class,it doesn't have  data type of  the value returned.2、construction method is used to instantiate an object and assign its attributes while common method is the action of object.

Tips:

Every system has a default construcion method,when we define a new construction method,the default is covered automatically.

 

Q6:What is method overloading?

A6:First is its conditions:1、method's name must be the same.2、parameter has at least one diffenfent aspect: number、type、sequence.Next is whywe need method overloading?For a easy example,some PC has camera inside while some doesn't.Their parameter is different  in the number.

 

Q7:What's the difference between passing by value and reference?

A7:Basic data tpye follows the rules of passing by value.Let's talk about passing by reference.Student st1  =new Student(); When we new Student(),it return the address,the address is assigned to the variable st1.So st1 points to the new object.

 

 

 

 

 
  • 大小: 9.9 KB
  • 大小: 6.5 KB
  • 大小: 6.2 KB
  • 大小: 5.8 KB
  • 大小: 4 KB
  • 大小: 7.7 KB
  • 大小: 8.6 KB
  • 大小: 3.8 KB
分享到:
评论

相关推荐

    C++程序设计教学课件:Chapter 3 class and object.ppt

    C++程序设计教学课件:Chapter 3 class and object 本节课程主要介绍C++程序设计中的类和对象,涵盖了面向对象编程、类和对象的定义、构造函数和析构函数、组合、静态成员、常量对象和常量成员函数等关键概念。 一...

    C 程序设计教学课件:Chapter 3 class and object.ppt

    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 and Object‘s init.html

    【解惑】类与对象的初始化问题 - 爪哇人

    Perl To Python Migration

    The book then looks at the core technologies behind the Python language, including the exception system for handling errors, the class and object orientation system for creating new classes and ...

    UML Classroom

    After a brief explanation of why modeling is an indispensable part of software development, the authors introduce the individual diagram types of UML (the class and object diagram, the sequence ...

    UML 2.0 in a Nutshell

    Class and Object, Use Case, Sequence, Collaboration, Statechart, Activity, Component, and Deployment Diagrams Extension Mechanisms The Object Constraint Language (OCL) If you're new to UML, a...

    Systems.Analysis.and.Design.An.Object-Oriented.Approach.with.UML.5th

    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面向对象学习总结.pdf

    2. 类和对象(Class and Object): 类是对象的蓝图,可以理解为一个模板,通过这个模板可以创建出具体的实例对象。在Python中,使用`class`关键字定义一个类。例如,`MyFirstTestClass`就是一个类。类可以有属性和...

    Costa-Tyros_Chinese1.pdf

    6. 类与对象(Class and Object): 在第十二章中,讲解了如何在Prolog中使用类和对象的概念。创建一个类(class),例如`account`,可以通过`new`操作生成对象(object)。`account`类有接口方法如`ssN`用于获取...

    Python之Class&Object用法详解

    Python中的Class和Object是面向对象编程的基本组成部分,它们在创建可复用的代码结构和实现模块化编程中扮演着重要角色。本文将详细介绍这两个概念及其相关的用法。 **类(Class)** 类是一种抽象的数据类型,它...

    3D-RCNN: Instance-level 3D Object Reconstruction via Render-and-Compare

    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 ...

    2023年11月系统架构设计师架构知识点集锦.pdf

    * 类与对象(Class and Object):指系统中的类和对象之间的关系。 * 线程、进程、并发(Thread, Process, Concurrency):指系统中的线程、进程和并发问题。 * 软件到硬件的映射(Software to Hardware Mapping):...

    Python_基础10~171

    8. **类与对象(Class and Object)**:Python是面向对象的语言,用`class`关键字定义类。例如: ```python class Person: def __init__(self, name, age): self.name = name self.age = age person1 = ...

    可视化面向对象建模技术-标准建模语言UML

    2. 类图和对象图(Class and Object Diagrams):描述系统中的类、接口和对象及其关系,包括继承、关联和聚合等。 3. 交互图:包括顺序图(Sequence Diagrams)和合作图(Collaboration Diagrams),展示对象之间的...

    C++标准教程PPT

    `Class and object (2).ppt`进一步深化了类和对象的主题,可能涵盖了构造函数、析构函数、封装、继承和多态等面向对象编程的关键概念。这部分内容对于理解和运用C++中的复杂设计模式至关重要。 另外,`C++实例——...

    Vcl.SuperObject_superobject_class_

    Vcl.SuperObject 是 Delphi 开发环境中一个用于处理 JSON 数据的库,其核心类为 SuperObject_class。这个库提供了一种高效且灵活的方式来创建、解析和操作 JSON 对象。在 Delphi 中,SuperObject 使得与 JSON 格式的...

    Learning Rich Features from RGB-D Images for Object Detection and Segmentation

    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 ...

    java编程的小游戏

    类与对象(Class and Object) 在代码示例中,我们看到了`Computer`类和`Game`类的定义。`Computer`类用于表示游戏中的计算机对手,其中包含了一个方法`showfist()`来随机生成一个代表石头、剪刀或布的手势。`Game...

    Object-Oriented Analysis and Design 第六章

    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 ...

    Class and Pointer_C++_pointer_class_

    下面我们将深入探讨"Class and Pointer"这个主题,主要关注C++中类中的指针使用。 首先,让我们理解类(class)的基本概念。类是C++中面向对象编程的基础,它定义了一组数据成员(变量)和成员函数(方法),这些...

Global site tag (gtag.js) - Google Analytics