CIT383
CIT383
Explain the term “ Object Oriented Programming Language” List three main features of Object
Oriented Programming. Outline three popular Object Oriented Languages
answer
Object-oriented programming (OOP) is a programming paradigm that uses “objects” – data structures
consisting of data fields and methods and their interactions to design applications and computer
programmes. Programming techniques may include features such as information hiding, data
abstraction, encapsulation, modularity, polymorphism, and inheritance. It was not commonly used in
mainstream software application development until the early 1990s.
(i) Information-hiding
(ii) Code re-use
(iii) Pluggability and debugging ease
(iv) Modularity
answer
Information-hiding: By interacting only with an object’s methods, the details of its internal
implementation remain hidden from the outside world
Code re-use: If an object already exists (perhaps written by another software developer), you can use
that object in your program. This allows specialists to implement/test/debug complex, task-specific
objects, which you can then trust to run in your own code.
Pluggability and debugging ease: If a particular object turns out to be problematic, you can simply
remove it from your application and plug in a different object as its replacement. This is analogous to
fixing mechanical problems in the real world. If a bolt breaks, you replace it, not the entire machine
Modularity: The source code for an object can be written and maintained independently of the source
code for other objects. Once created, an object can be easily passed around inside the system
What do you understand by the term class methods? List three (3) examples of methods
answer
class method is a method which is bound to the class and not the object of theclass. They have the
access to the state of the class as it takes a class parameter that points to the class and not the object
instance. It can modify a class state that would apply across all the instances of the class.
examples of methods are;
List the three (3) logical operators that can be directly overloaded for a class
answer
These are the NOT operator (!), the AND operator (&), the OR operator (|) and the exclusive OR or XOR
operator (^).
Overridden Method
Overridden methods are methods that are redefined within an inherited or subclass. They have the
same signature and the subclass definition is used
Local Variables
Local variables are variables that are declared in the body of a particular method, such variables can be
used only in that method. When that method terminates, the values of its local variables are lost
Instance Variables
Instance variable must be initialised to their default value before they are used. The syntax for declaring
an instance variable within a method is:
Datatype variablename;
Create a class Student that has a field birthdate which is of the date type.
The class should have methods that can display the first name, last name and the birth date of
students
answer
Explain the term Polymorphism and give example
answer
Polymorphism is the capability of an action or method to do different things based on the object that it
is acting upon. it is the third basic principle of object-oriented programming.there are two types of
polymorphism which are Overloading and overriding
example
Mention 2 (two) types of Polymorphism and explain them
answer
The two main types of polymorphism are overloaded method and overridden methods. Overloaded
methods are methods with the same name signature but either a different number of parameters or
different types in the parameter list. For example 'spinning' a number may mean increase it, 'spinning'
an image may mean rotate it by 90 degrees. By defining a method for handling each type of parameter
you achieve the effect that you want. Overridden methods are methods that are redefined within an
inherited or subclass. They have the same signature and the subclass definition is used.
use this diagram below to get what it means incase the parameters are changed.
with the diagram above,you should be able to evaluate or solve the question
since we finding the larger value here,the larger value here is -4 because -4 is larger than -8 by the
number system.therefore, Max(-4, -8) = -4
(ii) Min(-6,-9)
since we finding the minimum value here,the mininum value here is -9 because -9 is smaller than -6 by
the number system..therefore, Min(-6, -9) = -9
(iii) Pow(4, 2)
since we looking for the power here,we are looking for the value of 4 raise to the power 2 which is
indicated as 42 .therefore, Pow(4, 2) =16
(iv) Sqr(900)
since we looking for the square root here,we looking for the square root of 900 which is 30.therefore we
have Sqr(900) = 30
(v) ABS(-80)
since we looking for the absolute value of -80 here,the absolute value will be giving as the positive value
of the original value which is 80.therefore we have ABS(-80) = 80
x=Math.abs(-7.5);
since we looking at the absolute value of (-7.5) here,the absolute value will be giving as the positive
value of the original value which is 7.5.therefore we have Math.abs(-7.5) =7.5
x=Math.floor(-8.7)
since we looking at rounding the value of (-8.7) to the largest integer not greater than (-8.7),then we will
be having a solution as -9.therefore we have Math.floor(-8.7) = -9
x=Math.ceil(6.3)
since we looking at rounding the value of (6.3) to the smallest integer not less than (6.3),then we will be
having a solution as 6.therefore we have Math.ceil(6.3) = 6
x=Math.floor(4.1)
since we looking at rounding the value of (4.1) to the largest integer not greater than (4.1),then we will
be having a solution as 4.there we have Math.floor(4.1) = 4
x=Math.ceil(-2.5)
since we looking at rounding the value of (-2.5) to the smallest integer not less than (-2.5) ,then we will
be having a solution as -2.therefore we have Math.ceil(-2.5) = -2
the two parts of abstract data types are Data and operations
What are the characteristics of abstract data type (ADT)? Name three (3) of them.
answer
1. It exports a type.
2. It exports a set of operations. This set is called interface.
3. Operations of the interface are the one and only access mechanism to the type's data structure.
abstraction
Abstraction is the process or result of generalisation by reducing the information content of a concept or
an observable phenomenon, typically to retain only information which is relevant for a particular
purpose. For example, abstracting a leather soccer ball to a ball retains only the information on the
general ball attributes and behaviour.
A constructor is like a method but it differs from a method with attributes.list them
answer
- a constructor has no return type.
It cannot even return void.
- a constructor must have the same name as the class.
- a constructor that has no parameter is called a no argument constructor and the one that has
parameter is called an argument constructor