what are the oops concept in java explain with real time
examples

Answers were Sorted based on User's Feedback



what are the oops concept in java explain with real time examples..

Answer / srikanth acharya

The OOPs concepts are:-
Object:-An object can be considered a "thing" that can
perform a set of related activities. The set of activities
that the object performs defines the object's behavior. For
example, the hand can grip something or a Student (object)
can give the name or address.

Class:- A class is simply a representation of a type of
object. It is the blueprint/ plan/ template that describe
the details of an object. A class is the blueprint from
which the individual objects are created. Class is composed
of three things: a name, attributes, and operations.

public class Student
{
}
According to the sample given below we can say that the
student object, named objectStudent, has created out of the
Student class.

Student objectStudent = new Student();

Encapsulation or information hiding:-The encapsulation is
the inclusion within a program object of all the resources
need for the object to function - basically, the methods
and the data. In OOP the encapsulation is mainly achieved
by creating classes, the classes expose public methods and
properties. The class is kind of a container or capsule or
a cell, which encapsulate the set of methods, attribute and
properties to provide its indented functionalities to other
classes. In that sense, encapsulation also allows a class
to change its internal implementation without hurting the
overall functioning of the system. That idea of
encapsulation is to hide how a class does it but to allow
requesting what to do.

There are several other ways that an encapsulation can be
used, as an example we can take the usage of an interface.
The interface can be used to hide the information of an
implemented class.

IStudent myStudent = new LocalStudent();
IStudent myStudent = new ForeignStudent();

Abstraction and Generalization:-Abstraction is an emphasis
on the idea, qualities and properties rather than the
particulars (a suppression of detail). The importance of
abstraction is derived from its ability to hide irrelevant
details and from the use of names to reference objects.
Abstraction is essential in the construction of programs.
It places the emphasis on what an object is or does rather
than how it is represented or how it works. Thus, it is the
primary means of managing complexity in large programs.
Abstraction and generalization are often used together.
Abstracts are generalized through parameterization to
provide greater utility. In parameterization, one or more
parts of an entity are replaced with a name which is new to
the entity. The name is used as a parameter. When the
parameterized abstract is invoked, it is invoked with a
binding of the parameter to an argument.
Abstract classes, which declared with the abstract keyword,
cannot be instantiated. It can only be used as a super-
class for other classes that extend the abstract class.
Abstract class is the concept and implementation gets
completed when it is being realized by a subclass. In
addition to this a class can inherit only from one abstract
class (but a class may implement many interfaces) and must
override all its abstract methods/ properties and may
override virtual methods/ properties.

Inheritance:-Ability of a new class to be created, from an
existing class by extending it, is called inheritance.

public class Exception
{
}

public class IOException extends Exception
{
}

Polymorphism:-Polymorphisms is a generic term that
means 'many shapes'. More precisely Polymorphisms means the
ability to request that the same operations be performed by
a wide range of different types of things.

The method overloading is the ability to define several
methods all with the same name.

public class XYZ
{
public void Error(Exception e)
{
// Implementation goes here
}

public bool Error(Exception e, string message)
{
// Implementation goes here
}
The operator overloading (less commonly known as ad-hoc
polymorphisms) is a specific case of polymorphisms in which
some or all of operators like +, - or == are treated as
polymorphic functions and as such have different behaviors
depending on the types of its arguments.

Is This Answer Correct ?    2 Yes 4 No

what are the oops concept in java explain with real time examples..

Answer / nagarjuna.j

Encapsulation,
Abstraction class,
Polymorphism,
inhiertence..

Is This Answer Correct ?    2 Yes 4 No

what are the oops concept in java explain with real time examples..

Answer / suresh

oops concepts are mainly 3
1.encapsulation
2.inheritance
3.polymorphism

1 :- encapsulation refers to binding the data in a single
class the data present inside the encapsulation is secured.

abstraction comes under encapsulaton.

real time example:-if you get fever you will take the
medicine to cure.the medicine is the capsule in which the
powder is present.the powder is a mixture of several
chemicals as in the same way all the classes are mixed and
only the output(object) you will see as if a capsule.

2 :- inheritance is nothing but extending the class from
parent to the child

real time example:- the prime minister of india
(late)mr.jawaharlal nehru and his daughter indira gandhi
and her son rajiv gandhi and his wife sonia gandhi.

3 :- polymorphism refers to which it does many things

real time example:- consider the electric power which does
many things .

Is This Answer Correct ?    28 Yes 49 No

what are the oops concept in java explain with real time examples..

Answer / atif hossain

encapsulation
abstraction
interface
polymorphism
imheritance

Is This Answer Correct ?    35 Yes 70 No

Post New Answer

More Core Java Interview Questions

I want to print “hello” even before main is executed. How will you acheive that?

0 Answers  


Which is faster call by value or call by reference?

0 Answers  


Implementations of set interface?

0 Answers  


what is run time polymorphism

4 Answers  


Difference between notify() method and notifyall() method in java?

0 Answers  






What are the differences between graph and tree?

0 Answers   Amazon,


What are the important methods of java exception class?

0 Answers  


What is meant by class loader? How many types are there?

0 Answers  


What is the integer of 16?

0 Answers  


What is wrapper class example?

0 Answers  


Where import statement is used in a java program?

0 Answers  


What is OOPs & Why?

3 Answers  


Categories