Oop class Object Field



Download 1,54 Mb.
Sana16.06.2022
Hajmi1,54 Mb.
#677981
Bog'liq
New Microsoft PowerPoint Presentation

OOP

Class

Object

Field

Method

Class Fundamentals

  • A class is declared by use of the class keyword.
  • A class is a template for an object, and an object is an instance of a class.

The General Form of a Class

class classname{ type instance-variable1; type instance-variable2; //... type methodname1(parametr-list){ //body of method } type methodname2(parametr-list){ //body of method } }

Simple Class


class Box{ double width; double height; double depth; }
  • The methods and variables (instance variables) defined within a class are called members of the class.
  • lass declaration only creates a template; it does not create an actual object.

Declaring Objects

  • when you create a class, you are creating a new data type.
  • Obtaining objects of a class is a two-step process.
  • First, you must declare a variable of the class type. This variable does not define an object.
  • Second, you must copy of the object and assign it to that variable. You can do this using the new operator.

// declare reference to object

  • As mentioned earlier, each time you create an instance of a class, you are creating an object that contains its own copy of each instance variable defined by the class. Thus, every Box object will contain its own copies of the instance variables width, height, and depth.
  • To access these variables, you will use the dot (.) operator.
  • The dot operator links the name of the object with the name of an instance variable. For example, to assign the width variable of mybox the value 100, you would use the following statement:
  • mybox.width = 100;

Assigning Object Reference Variables

  • Box b1 = new Box();
  • Box b2 = b1;

Constructors


Download 1,54 Mb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish