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
How is it possible in java programming for two string objects with identical values not to be equal under the == operator?
How does hashset works in java?
What is the function of compareto in java?
If you do not want your class to be inherited by any other class. What would you do?
How do you create a reference in java?
What does the exclamation mark mean in java?
What design pattern you have used in your project? I answered Factory pattern, how it is implemented? What are its advantage? Do know about Abstract Factory?
What do you understand by Header linked List?
What is "this" keyword in java? Explain
How can you traverse a linked list in java?
What are the parts of methodology?
Explain methods specific to list interface?
Can an interface be final?
Why java is said to be pass-by-value ?
how can you take care of mutual exclusion using java threads? : Java thread