explain oops concepts with examples?

Answer Posted / dara

There are three types of oops in java.
1.Encapsulation:Encapsulation is mechanism,that binds
together data and code its manipulates.
Ex:suppose we are writing one bean.we declaring two private
variables.we are providing setters and getters methods of
two variables.These variables are accessed in that class.
2.Inheritance:To acquire the base class properties into
derived class.
Ex:class A{
m1(){
System.out.println("m1 method");
}
}
class B extends A{
m2(){
System.out.println("m2 method");
}
public static void main(String args[]){
B b = new B();
System.out.println(b.m1);
System.out.println(b.m2);
}
}
O/p is:m1 method
m2 method.
Polymorphism:one Interface to be used for a general class of
actions.
There are two types of polymorphisms.
1.Compile-time polymorphism:what object will be assigned to
the present variable.This will be evaluated at compile time.
This is known as compile-time polymorphism.
2.Run-time polymorphism:what object will be assigned to the
present variable.This will be evaluated at runtime depending
on condition.This is known as Run-time polymorphism.

Is This Answer Correct ?    363 Yes 101 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a qms manual?

537


What is exception in java?

563


Can we clone singleton object in java?

558


Is java a prime method?

548


How do you use spaces in java?

518






What is the largest long allowed by java?

530


What do you mean by garbage collection used in java?

567


What is java virtual machine and how it is considered in context of java’s platform independent feature?

647


What is java argument list?

516


Do we need to manually write Copy Constructor?

602


What is the function of compareto in java?

581


Can we have return statement in finally clause? What will happen?

510


What is a heavyweight component?

539


What is the meaning of find and replace?

520


What is a null point?

553