Sunday, June 17, 2012

What are the core OOP’s concepts?

  1. Abstraction
  2. Encapsulation
  3. Inheritance
  4. Polymorphism



Polymorphism, Inheritance and Encapsulation

Inheritance is the process by which one object acquires the properties of another object. Inheritance allows well-tested procedures to be reused and enables changes to

make once and have effect in all relevant places

Explain the Polymorphism principle. Explain the different forms of Polymorphism.
Polymorphism in simple terms means one name many forms.
Polymorphism exists in three distinct forms in Java:
• Method overloading
• Method overriding through inheritance
• Method overriding through the Java interface

method overloading is the primary way polymorphism is implemented in Java

overloaded methods:
appear in the same class or a subclass
have the same name but,
have different parameter lists, and,
can have different return types

an example of an overloaded method is print() in the java.io.PrintStream class
public void print(boolean b)
public void print(char c)
public void print(char[] s)
public void print(float f)
public void print(double d)
public void print(int i)
public void print(long l)
public void print(Object obj)
public void print(String s)



Overriding methods
appear in subclasses
have the same name as a superclass method
have the same parameter list as a superclass method
have the same return type as as a superclass method
the access modifier for the overriding method may not be more restrictive than the access modifier of the superclass method



Explain Encapsulation, Polymorphism and Inheritance.
http://www.youtube.com/watch?v=QzX7REqciPY




  • Inheritance - comes under Relationship -> Generalization/Specilization -> enables code resuability. But also enables maintanence nightmare of managing classes.

Polymorphism - comes unders Behaviour->Compile time/Runtime -> enables the varying behaviour of the operations depending upon the type of the object(runtime entity).

http://www.linkedin.com/groups/what-is-difference-between-dynamic-70526.S.217712129?view=&srchtype=discussedNews&gid=70526&item=217712129&type=member&trk=eml-anet_dig-b_pd-ttl-cn&ut=23CVDF6gnvwlE1

  • Class versus object
A class is a template for objects. A class defines object properties including a valid range of values, and a default value. A class also describes object behavior. An object is a member or an "instance" of a class. An object has a state in which all of its properties have values that you either explicitly define or that are defined by default settings.
https://www.ncl.ucar.edu/Document/HLUs/User_Guide/classes/classoview.shtml#:~:text=A%20class%20defines%20object%20properties,are%20defined%20by%20default%20settings.

  • Let's see some real life example of class and object in java to understand the difference well:

Class: Human Object: Man, Woman

Class: Fruit Object: Apple, Banana, Mango, Guava wtc.

Class: Mobile phone Object: iPhone, Samsung, Moto

Class: Food Object: Pizza, Burger, Samosa

https://www.javatpoint.com/difference-between-object-and-class

No comments:

Post a Comment