KEJDJFHSJ
KEJDJFHSJ
VARIABLE
Add a short description
11:11P
M
Topics Covered
Topic 1 Topic 2
TOPICS
Topic 3
What is Class Variable?
Is a variable that belongs to the class
itself, rather than to any particular
instance
of the class.
Example:
class Car:
# class variable
wheels = 4
def description(self):
print(f"This car is a {self.make} {self.model}
with {Car.wheels} wheels.")
Class variables are defined inside the class
definition, but outside any method, and are
accessible to all instances of the class.
Section Header • Section Header • Section Header • Section Header • Section Header • Section Header • Section Header • Section Header
INHERITANCE
Back to Agenda Page
Section Header • Section Header • Section Header • Section Header • Section Header • Section Header • Section Header • Section Header
What is INHERITANCE?
Is a key concept in object-oriented
programming (OOP) that allows a class to
inherit properties and behaviors from a
parent or superclass. This can save a lot of
time and effort in coding.
In addition, it allows developers to
reuse code and avoid duplicating
functionality.
In Java, inheritance is implemented
through the use of the extends
keyword.
1. Code reuse: Inheritance allows you to
reuse code from an existing class by creating
a subclass that extends it. This saves time and
effort by reducing the amount of code you
need to write.
2. Polymorphism: Inheritance enables
polymorphism, which means that you can use a
subclass object wherever a superclass object is
expected. This makes your code more flexible
and easier to maintain.
3. Simplified code: Inheritance simplifies
your code by allowing you to create a
hierarchy of classes that share common
properties and behaviors.
4. Increased flexibility: Inheritance makes it easier to
add new functionality to your code by creating a new
subclass that inherits from an existing class. This
allows you to modify or extend the behavior of the
original class without changing its code.
Example:
public class Animal {
private String name;
private int age;
--instances
local manager = Manager:new("Jenny")
print(manager:getName()) --> Jenny