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

Is java good for beginners?

583


How do you create a reference in java?

514


What are the advantages of java over C++?

721


Why unicode is important?

469


What is Recursion Function?

650






Is 0 a prime number?

575


what is the use of pojo (plain old java objects)? how it is interact with crystal reports? pls urgent

1737


Can I overload to string method

973


What are the fileinputstream and fileoutputstream?

571


What is a subsequence of a string?

551


What is cr keyboard?

659


Why runnable interface is used in java?

578


Does set allows null in java?

510


Explain about interrupt() method of thread class ?

666


how a programmer confirms that the data submitted has been succesfully inserted into the database(either oracle or my sql).. How a programmer confirm if there is any problem with the program he wrote for insertion... ANS:--- >executeupdate method is having boolean return type, if anything goes wrong in data insertion or data updation, it would return false. otherwise, if it successfully inserts data into the database, it would return true NOW HOW TO I CHECK IN MY DURING EXECUTION WHETHER IT RETURNS TRUE OR FALSE... WELL IT WILL DISPLAY ANY MESSAGE OR NOT

1856