Advance Object Oriented Programming (Lecture 1) : Ms. Sehresh Khan Lecturer Numl-Rwp

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 13

Advance Object Oriented Programming

(Lecture 1)

Ms. Sehresh Khan


Lecturer
NUML-RWP
Administrative Details
 Title
◦ Advance Object Oriented Programming
 Credit Hours
◦ (3,1)
 Prerequisite
◦ FoP, OOP
 Google classroom id:
◦ Section A: jnwemio
◦ Section B: himcuj3
Course Contents
 Object Oriented Programming Techniques
◦ Encapsulation, Composition, Inheritance,
Polymorphism, Templates, Interfaces, Exception
Handling

 Event driven Programming


◦ Graphical user interface programming, Events,
Event handlers

 Advanced topics of OOP


◦ Serialization, multithreading, MVC Architecture
Object Oriented Programming
 Object Oriented Programming (OOP) is
a programming model where programs are
organized around 
◦ Objects and data
 rather than
◦ Action and logic. 

 OOP allows decomposition of a problem into a


number of entities called objects and then
builds data and functions around these objects.
class
 A class in C++ is the building block, that
leads to Object-Oriented programming.

 It is a user-defined data type, which holds its


own data members and member functions,
which can be accessed and used by creating
an instance of that class.

 A C++ class is like a blueprint for an object.


Object
 Anything which possess some
charachterstocs and functionalities is called
object.
 Can be a person, place or concept
 An Object is an instance of a Class. When a

class is defined, no memory is allocated but


when it is instantiated (i.e. an object is
created) memory is allocated.
Encapsulation

 Encapsulation is defined as
wrapping up of data and
information under a single
unit. In Object Oriented
Programming, Encapsulation
is defined as binding
together the data and the
functions that manipulates
them.
Access Specifiers
In C++, there are three access
specifiers:
 public - members are accessible

from outside the class


 private - members cannot be

accessed (or viewed) from


outside the class
 protected - members cannot be

accessed from outside the class,


however, they can be accessed
in inherited classes. (You will
learn more about it in
Inheritance later.)
Constructor
A constructor is a special type of member function that is
called automatically when an object is created.

 Its purpose is Initialization


 No return type...not even void
 Its name should be same as of class name
 It can not be called explicitly, only will be called by complier
whenever an object is created.
 Every class must have a no-argument constructor
◦ when programmer do not create any constructor then a no-
argument constructor is always created by compiler which is known
as default constructor
 Can be overloaded for different number/type of parameters
Classes and main function
 public class Student {
     int id;
     String name;
 }

 class Main {
     public static void main(String[] args)
     {
         Student myObj = new Student();
         System.out.println(myObj.id);
 //syso ctrl+space
     }
 }
Class Constructor
 public class Student {
     int id;
     String name;
     
     public Student()
     {}
     public Student(int i, String n)
     {
         id=i;
         name=n;
     }
 }

 class Main {
     public static void main(String[] args)
     {
         Student myObj = new Student(1234, "Ahmad");
         System.out.println(myObj.id);
     }
 }
Class member function
 public class Student {
     int id;
     String name;
     
     public Student()
     {}
     public Student(int i, String n)
     {
         id=i;
         name=n;
     }
     public void show()
     {
         System.out.println(id);
         System.out.println(name);
     }
 }
 class Main {
     public static void main(String[] args)
     {
         Student myObj = new Student(1234, "Ahmad");
         myObj.show();
     }
 }
Access Specifiers
 public class Student {
     private int id;
     private String name;
     
     public Student()
     {}
     public Student(int i, String n)
     {
         id=i;
         name=n;
     }
     public void show()
     {
         System.out.println(id);
         System.out.println(name);
     }
 }
 class Main {
     public static void main(String[] args)
     {
         Student myObj = new Student(1234, "Ahmad");
         myObj.show();
     }
 }

You might also like