0% found this document useful (0 votes)
54 views

Assignment 2 Oop

Class is a blueprint that defines common properties and behaviors of objects. It allows for object creation, inheritance and code reuse. An object is an instance of a class that packages together related properties and methods. The 'this' keyword refers to the current object and is used to distinguish class attributes from parameters. Static means a variable or method belongs to the class itself rather than objects. Inheritance is a mechanism where a derived class acquires properties and behaviors of its base class while allowing independent extension.

Uploaded by

hammad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Assignment 2 Oop

Class is a blueprint that defines common properties and behaviors of objects. It allows for object creation, inheritance and code reuse. An object is an instance of a class that packages together related properties and methods. The 'this' keyword refers to the current object and is used to distinguish class attributes from parameters. Static means a variable or method belongs to the class itself rather than objects. Inheritance is a mechanism where a derived class acquires properties and behaviors of its base class while allowing independent extension.

Uploaded by

hammad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Minhaj University Lahore

Submitted by:
Hammad Saeed
Submitted to:
Sir Saif Ali
Roll no:
69
Class:
BSCS (B) 6TH SEMESTER
Subject:
Object Oriented Analysis and Design
What is class?

In object-oriented programming, a class is a blueprint for creating objects (a particular data


structure), providing initial values for state (member variables or attributes), and
implementations of behavior (member functions or methods). The user-defined objects
are created using the class keyword. The class is a blueprint that defines a nature of a
future object. An instance is a specific object created from a particular class. Classes are
used to create and manage new objects and support inheritance. A key ingredient in
object-oriented programming and a mechanism of reusing code.

What is an object?

An object, in object-oriented programming (OOP), is an abstract data type created by a


developer. It can include multiple properties and methods and may even contain other
objects. In most programming languages, objects are defined as classes. Objects provide a
structured approach to programming. By defining a dataset as a custom object, a
developer can easily create multiple similar objects and modify existing objects within a
program. Additionally, objects provide "encapsulation," meaning the data within an object
is protected from being modified or destroyed by other functions or methods unless
explicitly allowed.

What does the this keyword refer to when used inside a class?

The this keyword refers to the current object in a method or constructor. The most
common use of the this keyword is to eliminate the confusion between class attributes and
parameters with the same name (because a class attribute is shadowed by a method or
constructor parameter). If you omit the keyword in the example above, the output would
be "0" instead of "5".

This can also be used to:

Invoke current class constructor

Invoke current class method

Return the current class object

Pass an argument in the method call

Pass an argument in the constructor call


What does the static keyword mean?

When static keyword is used, variable or data members or functions cannot be modified
again. It is allocated for the lifetime of program. Static functions can be called directly by
using class name. Static variables are initialized only once. Compiler persist the variable till
the end of the program. Static variable can be defined inside or outside the function. They
are local to the block. The default value of static variable is zero. The static variables are
alive till the execution of the program.

What is inheritance?

In object-oriented programming, inheritance is the mechanism of basing an object or class


upon another object (prototype-based inheritance) or class (class-based inheritance),
retaining similar implementation. Also defined as deriving new classes (sub classes) from
existing ones such as super class or base class and then forming them into a hierarchy of
classes. In most class-based object-oriented languages, an object created through
inheritance, a "child object", acquires all the properties and behaviors of the "parent
object" , with the exception of: constructors, destructor, overloaded operators and friend
functions of the base class. Inheritance allows programmers to create classes that are built
upon existing classes to specify a new implementation while maintaining the same
behaviors (realizing an interface), to reuse code and to independently extend original
software via public classes and interfaces. The relationships of objects or classes through
inheritance give rise to a directed graph.

You might also like