Java Object Oriented Concepts
Object-Oriented Programming conceptObject-oriented Programming is designed to model the real world concept into a computer program.It considers real world things as object.Ex. Bicycle,car,book and so on.
This is an approach that provides a way of modularizing program by creating partitioned memory area for both data and function that can be used as templates for creating copies of such modules on demand.
The OOP Principles
- Abstraction:
- Encapsulation: Wrapping up of data and method into a single unit is known as encapsulation
An object is something similar. It is created with the immense power of a class. while the composition of the class could be anything (as compared to the capsule), one may not know what is contained when you create the object handle
as in
A obj = new A();
you may say obj here is like the capsule to all those who want to consume it in their programs.
So, with this object one can use its inherent power.
Thus this concept of hiding away its true power is known as Encapsulation
- inheritance:The mechanism of deriving a new class from an old one is called inheritance.The old class is known as base class or super class or parent class and new class is called the subbclass or derived class or child class.
Different Types of Inheritance
- Single inheritance(only one super class)
- Multiple inheritance(several super classes)
- Hierarchical inheritance(one super class, many subclasses)
- Multilevel inheritance(Derived from a derived class)
Defining a subclass:
syntax:
class subclassname extends superclassname
{
varialbe declaration;
method declaration;
}
{
varialbe declaration;
method declaration;
}
The keyword extends is used to inherit the properties of base class to derived class.
Ex.
class User
{
private String name;
public void setName(String n)
{
name = n;
}
public String getName()
{
return name;
}
}
{
private String name;
public void setName(String n)
{
name = n;
}
public String getName()
{
return name;
}
}
class Student extends User
{
private String stuNum;
public void setStuNum(String sn)
{
stuNum = sn;
}
public String getStuNum()
{
return stuNum;
}
}
{
private String stuNum;
public void setStuNum(String sn)
{
stuNum = sn;
}
public String getStuNum()
{
return stuNum;
}
}
Finally we have to create a program that will instantiate a Student object, set the name and student number and then print the values using the get methods.
public class TestInheritance
{
public static void main(String[] args)
{
Student stu = new Student();
stu.setName("John Smith");
stu.setStuNum("12345");
System.out.println("Student Name: " + stu.getName());
System.out.println("Student Number: " + stu.getStuNum());
}
}
{
public static void main(String[] args)
{
Student stu = new Student();
stu.setName("John Smith");
stu.setStuNum("12345");
System.out.println("Student Name: " + stu.getName());
System.out.println("Student Number: " + stu.getStuNum());
}
}
- Polymorphism:It means "one interface,multiple methods".The ability to take more than one form.
EX. An operation show different behaviour in different instance.
consider the operation of addition,for 2 no,the operation will generate sum.If the operands are string ,then the operation would produce a third string by concatenation.
Application OF OOP:
- Real-time system
- Simulation and modelling
- Object-oriented datbase
- Hypertext,hypermedia and expertext
- AI and expert system
- Neural network and parallel progarmming
- Decision support and office automation system
- CIM/CID/CAD system
Benefits Of OOP
- Through inheritance, we can eliminate redundant code and extend the use of existing classes.
- We can build secure programs using data hiding concept.
- It is easy to parition the work in project based on object.
- Software complexity can be easily managed.
Back To Java Home
Back To Home
Sidebar
Last wiki comments
- Introduction to ORM: ugg boots
- Introduction to ORM: ugg boots
- AOP: Thanks
- Lalit Bhatt: Superb Collection
- Lalit Bhatt: J2EE training
- Introduction to ORM: timberland shoes
- Introduction to ORM: jordan shoes
- Introduction to ORM: nike air max
- Pune Tourist Spots: KONARK PARK CLOSED
- jQuery Form Validations: Jquery Developer
Sidebar
Random Pages
- What markets work on?
- Why projects fail?
- Bharat Band - Jai ho
- The concept of Nation
- Don't hide complexity if it cannot be handled in a robustway
Last blog post comments
-
Prospective MLA for Pune election - 2009: ugg boots
Wed 01 of Sep., 2010 12:58 IST
-
Bharat Band - Jai ho: How do we protest?
Wed 18 of Aug., 2010 13:13 IST
-
Divided by Destiny: Contact
Fri 23 of July, 2010 16:02 IST
-
Future of Java: thesis writing
Sat 17 of July, 2010 01:50 IST
-
Hang till Death Mr. Kasab: some change
Mon 28 of June, 2010 16:03 IST
-
God Religion : Why we are confused?: Re: Is GOD Necessary?
Tue 15 of June, 2010 17:29 IST
-
God Religion : Why we are confused?: Is GOD Necessary?
Tue 15 of June, 2010 13:06 IST
-
The reason in religion: good
Wed 10 of Mar., 2010 18:30 IST
-
The confusion of Design Patterns: I think at macro level you are right...
Tue 23 of Feb., 2010 03:31 IST
-
The Indian Municipality: Comment
Fri 22 of Jan., 2010 13:20 IST
Post new comment