Opps Concepts in java?

What is Class in java?
The process of binding data members and methods in a single unit is known as class.
Syntax to declare a class:
class      <name of the class>
{
    declare  data member;
    declare method;
}
Example:
public class Employee
{        
   String name;    
   int  age;                      
   double sal;
  public void getEmpDetails(int age,String name,double sal)
  {
   this.age=age;
   this.name=name;
   this.sal=sal;
  }
  public void displayEmpDetails()
  {
   System.out.println( name + " " +   age + " " + sal  );
  }
 
   public static void main(String args[])
{
  
                 Employees  obj=new Employee();

                 obj.getEmpDetails(22,"mahesh", 20000.00);

                 obj.displayEmpDetails();
}
}

What is Object in java?
An entity that has state and behavior is known as an object 
An object holds both variables and methods
state: represents data (value) of an object.
behavior: represents the behavior (functionality) of an object such as deposit, withdraw etc.
Example: A Customer has states – name, account no, address as well as behavior such as withdraw, deposit. 
Object is an instance of a class. Class is a template or blueprint from which objects are created. So object is the instance (result) of a class.
Example:  Customer customer=new Customer ();

What is Encapsulation in java?
Encapsulation means it is a mechanism of wrapping up of data (variables) and methods together as a single unit is know as Encapsulation. 
In encapsulation, the variables of a class will be hidden from other classes, and it can be accessed  through the methods of their current class. Therefore, it is also known as data hiding.
What is Abstraction in java?
Abstraction is process of hiding the implementation details and  just showing only the functionality. to the user is nothing but Abstraction.
Abstraction can be  achieved by using interface and abstract class. 
Interface give 100% abstraction and abstract class give 0-100% abstraction.
What is inheritance in java?
Inheritance means The process of obtaining the data members and methods from one class to another class is known as inheritance. It is one of the fundamental features of object-oriented programming.
Important points
In the inheritance the class which is give data members and methods is known as base or super or parent class.
The class which is taking the data members and methods is known as sub or derived or child class.
The data members and methods of a class are known as features.
The concept of inheritance is also known as re-usability or extendable classes or sub classing or derivation.

Why use Inheritance ?
For Method Overriding (used for Runtime Polymorphism).
It's main uses are to enable polymorphism and to be able to reuse code for different classes by putting it in a common super class
For code Re-usability
A super-class can have any number of subclasses. But a subclass can have only one super class. Java does not support multiple inheritance.
The super class and subclass have “is-a” relationship between them. Let’s have a look at the 
Advantage of inheritance
If we develop any application using concept of Inheritance than that application have following advantages,
Application development time is less.
Application take less memory.
Application execution time is less.
Application performance is enhance (improved).
Redundancy (repetition) of the code is reduced or minimized so that we get consistence results and less storage cost.
Note: In Inheritance the scope of access modifier increasing is allow but decreasing is not allow. Suppose in parent class method access modifier is default then it's present in child class with default or public or protected access modifier but not private(it decreased scope).


Tpyes of Inheritance
Based on number of ways inheriting the feature of base class into derived class we have five types of inheritance; they are:
Single inheritance
Multilevel inheritance
Multiple inheritance
Hierarchical inheritance
Hybrid inheritance
What is Polymorphism in java?
The process of representing one form in multiple forms is known as Polymorphism.
Polymorphism is derived from 2 greek words: poly and morphs. The word "poly" means many and "morphs" means forms. So polymorphism means many forms.
Polymorphism is not a programming concept but it is one of the principal of OOPs. For many objects oriented programming language polymorphism principle is common but whose implementations are varying from one objects oriented programming language to another object oriented programming language.
How to achieve Polymorphism in Java ?
In java programming the Polymorphism principal is implemented with method overriding concept of java.
Polymorphism principal is divided into two sub principal they are:
Static or Compile time polymorphism
Dynamic or Runtime polymorphism
Note: Java programming does not support static polymorphism because of its limitations and java always supports dynamic polymorphism.
Following concepts demonstrate different types of polymorphism in java.
Polymorphism means more than one form, same object performing different operations according to the requirement.
Polymorphism can be achieved by using two ways, those are
Method overriding
Method overloading
Method overloading means writing two or more methods in the same class by using same method name, but the passing parameters is different.
Method overriding means we use the method names in the different classes,  that mean parent class method is used in the child class.




Share:

No comments:

Post a Comment

Ordered List

Popular Posts

The Magazine

Facebook

Post Top Ad

LightBlog

Post Top Ad

Your Ad Spot

About Me

authorHello, my name is Jack Sparrow. I'm a 50 year old self-employed Pirate from the Caribbean.
Learn More →

Comment

Post Top Ad

Your Ad Spot

Hot

AD BANNER

Sponsor

AD BANNER

Recent Comments

Extra Ads

AD BANNER

Contact Form

Name

Email *

Message *

Translate

Sponsor

test

Home Top Ad

Responsive Ads Here

Flickr

Ad Banner
Responsive Ads Here

About Us

authorHello, my name is Jack Sparrow. I'm a 50 year old self-employed Pirate from the Caribbean.
Learn More →

Recent Posts

Unordered List

  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  • Aliquam tincidunt mauris eu risus.
  • Vestibulum auctor dapibus neque.

Sample Text

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation test link ullamco laboris nisi ut aliquip ex ea commodo consequat.

Pages

Theme Support

Need our help to upload or customize this blogger template? Contact me with details about the theme customization you need.