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 does localhost mean?

487


Is {a, n, d} a palindrome? If you are given a random string, is it a palindrome or not?

617


What are the loops in java?

515


For ease of programming you can consider the maze as a 2D array with colors represented by below integer and characters (in capital letters). • B - Black • W -White • G- Green • R- Red R B W B W W W W W W B W B B W W W W W W W B W B W W W B W W W W B B W W W B W W W B W W B B B B W B W B W W B W W W B W W W B B B W W B W W W B W W B W B W W W B W B W W W W B B W W W W B W W W W W G Shortest Route Problem: • Solution that finds the shortest Route between Red and Green  White will have 1 Weight.  Red and Green carry no weights.  Shortest path is the path with less weight when you add up the weights in the path.

1577


What is arguments in java?

513






What is a byte string?

610


what is method reference in java 8?

550


What is the use of using enum to declare a constant?

548


Can we assign integer value to char in java?

505


What is udp in java?

528


What are assembly attributes?

538


What are the important features of Java 8 release?

569


Why are functions called methods in java?

518


What is the difference in between cpp and java? Can u explain in detail?

598


Is integer a class?

560