logo

Object Oriented Programming with C#

Name two principles of Object Oriented Programming and write a C# class to calculate the area of a rectangle.

6 Pages690 Words365 Views
   

Added on  2023-06-11

About This Document

This article discusses the principles of Object Oriented Programming with C# and how to implement them. It includes a sample code for a Rectangle class and a driver class. The article also explains the concepts of inheritance and polymorphism.

Object Oriented Programming with C#

Name two principles of Object Oriented Programming and write a C# class to calculate the area of a rectangle.

   Added on 2023-06-11

ShareRelated Documents
Running head: OBJECT ORIENTED PROGRAMMING WITH C#
Object Oriented Programming with C#
Name of the student:
Name of the University:
Author note:
Object Oriented Programming with C#_1
1
OBJECT ORIENTED PROGRAMMING WITH C#
Table of Contents
Task 1...............................................................................................................................................2
Task 2...............................................................................................................................................3
Rectangle Class (Rectangle.cs)....................................................................................................3
Driver class (Calculate.cs)...........................................................................................................3
Output..........................................................................................................................................4
Object Oriented Programming with C#_2
2
OBJECT ORIENTED PROGRAMMING WITH C#
Task 1
Two main principles of Object Oriented Programming are:
Inheritance: This is the process by which classes within the same package can inherit
certain characteristics and behaviors from leading or existing classes. It is the child class
that is known to inherit the accessible properties from the parent class, also known as the
root class. The concept of inheritance helps to conceptualize the hierarchical
classification of classes and objects. Though inheritance, programmers can manage to re-
use various sections of the code. This helps in the reducing space complexity of
programs, as the redundant information and functionalities can be inherited from the
existing classes. These data or method members are initialized once in the parent classes
and are then used by the instances of the child classes. The accessibility of these members
in the child classes depends on the access specifiers of these members. Public data
members can be accesses by all classes of the package, protected members can only be
accessed by the child classes and private members cannot be accessed outside the same
class (Smith, 2015).
Polymorphism: Polymorphism is the term that is used to describe the quality of an
element that allows it to exist in more than one form. In object oriented programming,
polymorphism refers to the ability via which more than one method are able to exist with
the same name but performing a different set of actions. This is done through passing a
variety of parameter or argument types and numbers. There are two types of
polymorphism namely, static polymorphism and dynamic polymorphism. Method or
constructor overloading is the form of static polymorphism. Through this, multiple
method instances can be created to perform a variety of operations however they contain
Object Oriented Programming with C#_3

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Object Oriented Programming in Aviation Airlines
|8
|1302
|148

Assignment on Object Oriented Programming
|7
|477
|169

Assignment on Explaining Polymorphism
|11
|1647
|313

Programming - Tutorial 7
|6
|1020
|171

OBJECT ORIENTED PROGRAMMING.
|5
|369
|484

Object Oriented Programming: Inheritance, Encapsulation, Polymorphism
|11
|1451
|340