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 to print nodes of a Binary tree?
Explain method local inner classes ?
when to use ArrayList and when to use HashMap in webApplication.
what is enumset?
Can a string be null?
What is the difference between Java1.4 and Java1.5
What does the “static” keyword mean?
What is outofmemoryerror in java?
What is a stringbuffer?
What is polymorphism in java? What are the kinds of polymorphism?
What is a java lambda expression?
What is the final keyword in java?
Can a static class have a constructor?
Is there any way to find whether software installed in the
system is registered by just providing the .exe file?
I have tried the following code but its just displaying the
directory structure in the registry.
Here the code :
package com.msi.intaller;
import java.util.Iterator;
import ca.beq.util.win32.registry.RegistryKey;
import ca.beq.util.win32.registry.RootKey;
public class RegistryFinder {
public static void main(String... args) throws Exception
{
RegistryKey.initialize(RegistryFinder.class.getResource("jRe
gistryKey.dll").getFile());
RegistryKey key = new RegistryKey(RootKey.HKLM,
"Software\\ODBC");
for (Iterator
What are the benefits of immutable objects?