A class is a template for objects, and an object is an instance of a class.
When the individual objects are created, they inherit all the variables and methods from the class.
Attributes are First Name, Last Name, Date of Birth, Profession, Address etc.
Methods can be "Change of address", "Change of Profession", " Change of last name" etc. "Change of last name" is generally applicable to women when they change their last name after marriage
Attributes are Breed, Number of legs, Size, Age, Color etc.
Methods can be Eat, Sleep, Sit, Bark, Run etc.
In python, we can create a class using the keyword class.
Method of class can be defined by keyword def. It is similar to a normal function but it is defined within a class and is a function of class. The first parameter in the definition of a method is always self and method is called without the parameter self.
__init__ is a method which is immediately and automatically called after an instance has been created. This name is fixed and it is not possible to chose another name. __init__ is one of the so-called magic methods,we will get to know it with some more details later. The __init__ method is used to initialize an instance. There is no explicit constructor or destructor method in Python, as they are known in C++ and Java. The __init__ method can be anywhere in a class definition, but it is usually the first method of a class, i.e. it follows right after the class header.a
Object and Method Example
Semua hal dianggap object
Object dapat digrouping(Class(template)
Contoh, manusia<==instance. Object dapat berinteraksi satu dengan yang lain, kapanpun.
Class dapat berinteraksi (template).
Ada 2 buah nilai:
atribute: name, power,defence.amor
method: hal-hal yang bisa dilakukan oleh hero: Menyerang, bertahan,bergerak
Class dideklarasikan sebelum program utama.
Class is template
we have 2 objects,
object1 and object2
example object is button, so button1(start), button2(stop) etc
attribute of button: text, color, size
method of button: click, redirect, alert, user do
there are 2 methods:
with client(interactive): object move
with other object: attact
Part 1
Part 2
Data Abstraction = Data Encapsulation + Data Hiding
Add build_year: