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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is unicode datatype?

531


Write a java program to generate fibonacci series ?

574


Do I need to import java.lang package any time? Why?

741


Explain the scope or life time of class variables or static variables?

519


How do you include a string in java?

524






Does google use java?

540


What is the difference between scrollbar and scrollpane?

610


Explain about anonymous inner classes ?

580


What is widening and narrowing in java? Discuss with an example.

558


From the two, which would be easier to write: synchronization code for ten threads or two threads?

615


what are different ways in which a thread can enter the waiting state? : Java thread

494


What is a map? What are the implementations of map?

565


What is string english?

545


What is difference between static and abstract class?

520


What is the difference between jvm and jre? What is an interface?

553