Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Â
Basics of object oriented programming interview tips for Java
1. Basics of Object Oriented
Programming
Dr.A.Martin, ME, Ph.D.
Assistant Professor,
Dept. of Computer Science,
School of Mathematics and Computer Sciences,
Central University of Tamil Nadu,
Thiruvarur, Tamilnadu-610 101.
2. Agenda
• Structured Programming
• Limitations in Structured Programming
• Object Oriented Programming
• Classes and Objects
• OOP’s Principles
• Static and Non Static Data
• Accessibility
• Exception Handling and Templates
3. Structured Programming
• It employs a top-down design model - map
out the overall program structure into
separate subsections.
• A defined function or set of similar functions
is coded in a separate module or sub module.
• Most famous for removing or reducing flaws
on the GOTO statement.
• E.g. C – The Programming Language.
4. Limitations in structured programming
• Data hiding
• Debugging of programs are hard
– Not Possible to handle run time errors and future
enhancements.
• Non Flexibility of Code
– In procedural programming, parts of code are
interdependent.
– This interdependency makes modification &
manipulation of a particular part of the program
without affecting other parts.
5. Limitations in structured programming
• Software development period is high.
• Software cost is high.
• If end user requirement changes a big
modification is needed in software
• More stress laid on procedures not on data
6. Object Oriented Programming
• In object oriented programming data and the
instruction for processing that data are
combined into a self-sufficient “object” that
can be used in other programs.
• It is a programming methodology used to
solve and develop complex problems by using
oops principles.
• Real world objects
• Software Objects
• Mapping of Real objects to software objects.
7. Class and Objects
• A Vehicle – A Car
• Mechanism – Break System, Radiator Cooling
System, Auto Door Lock, Air Conditioning, Safety
System, Security Mechanism, Gear Mechanism,
etc.,
• Spare Parts - Tires, Number of Tires, Head Light,
Density of air in tiers, Switch, window, door,
Number of windows and doors, Number of
seats.
• Car created with mechanism and spare parts.
• So many types – all from same car – differs in
flexibility and luxuries.
8. • Class – The bundling of data and functions
that acting on data on a single place.
• Class is a mould upon which objects are
created.
• The logical thing class is invoked by the real
thing object.
• The instance of the class is object.
10. Encapsulation – A rigid wall
• The binding of data and functions together to
achieve information hiding and modularity.
• Not allowed to enter.
• Not same kind of restriction to everyone.
• We want to some level of flexibility.
• Accessibility – access specifiers
• Public , Private and Protected
• Default.
11. Inheritance
 It allows the creation of hierarchical classifications.
 Using inheritance, you can create a general class that
defines common properties.
 This class may then inherit by more specific classes,
each adding only those things that are unique to the
inheriting class.
 The process of creating new classes from existing
classes.
 A class that inherited is referred to as a base class.
 The class that does the inheriting is called derived
class.
12. Benefits,
 New classes can be derived by the user
from the existing classes without any
modification.
 It saves time and money.
 It reduces program coding time.
 It increases the reliability of the program.
13. Types of Inheritance
 Single : one base class and derived class
 Multiple : Many base class to one derived
class
 Multilevel : derived classes in a sequential
order
 Hierarchical : one base class and many
derived class
 Hybrid : A class derived from a base class
and an inheritance class
14. Polymorphism
• One interface with different forms
• Moving of a vehicle – Energy required.
• Energy available in different forms
• Fuel – Petrol, Diesel, Solar, Electric – Battery.
• Objective – Moving – achieved with different
ways.
• Compile time polymorphism and Run time
polymorphism.
15. Compile time polymorphism and Run time
polymorphism.
• Function overloading
 Same function with different arguments
Sum(int a ,int b)
Sum (double a, double b)
Sum (double a, double b, double c)
Sum (int a, long b)
 Need not worry about return type.
16. Function overriding
• Both base class and sub class have the
identical function.
• Same name, same number of arguments,
same data type.
• The function which is available in derived class
overrides the function in base class – called as
function overriding.
17. Static and Non Static Data
• Single copy shared by all instances
• Individual copy for every object
• How objects created for a class.
• How memory is allocated and reclaimed for
objects.
• Garbage collection.
• Constructor and Destructor. [C++]
• Constructor and Garbage Thread [Java].
20. Templates
• Templates are mechanism that make it
possible to use one function or class to handle
different data types.
• Function Template
• Class Template