Usually we find that for a java professional, OOPS concept is the
foremost question asked in interview. Mostly this question is raised as
the first question least bothering you are a fresher or experienced.As
we know that answer to first question in a well manner judge a lot about
you and also it boost up your energy for the coming question.
So i tried to present the answer in a well mannered way for interview purpose:
Question may be asked like Explain OOPS concept or What do you mean by saying OOPS....
Ans- OOPS stands for Object oriented programming system which communicates with object. Some of the languages which follows oops concept is Java,C++,LISP .
Concept under OOPS includes A-PIE i.e Abstraction, Polymorphism, Inheritance and Encapsulation.
Abstraction is a way to hide the implementation details and showing only the essential features of a method . in java abstraction can be achieved using abstract class and interface.
Polymorphism is the ability to have more than one form or using object in more than one way. Best example of polymorphism is + operator which can be used as string concatenation as well for adding 2 operands. In java there are 2 kinds of polymorphism: Run time-Method Overriding and Compile time-Method Overloading.
In case of method overriding a method in subclass overrides the method properties of the superclass. In overriding a method in subclass must have same argument list, it must have same return type or subtype of return type of superclass. it must have same access modifier or less restrictive than superclass method and finally a override method should not throw the new or broader checked exception compare to overridden method.
In case of method overloading a method in subclass must have different argument list, it can have different return type and can have different access modifier.Also it can throw broader checked exception.
Inheritance is a process by which a subclass inherits the properties of its superclass by accessing the variables or methods of the superclass. there are 3 types of inheritance, Single inheritance which is achieved by using extends keyword. Multiple inheritance is not supported directly by java but it can be achieved using interface as 1 class can implement more than 1 interface.
Inheritance provides code reusability.
Encapsulation is defined as wrapping up of data and method together, the best example of encapsulation is java class which have variables and method implementing those variables.
This flow you have to maintain for answering OOPS concept.
Hope you find it useful. BYE BYE......................
So i tried to present the answer in a well mannered way for interview purpose:
Question may be asked like Explain OOPS concept or What do you mean by saying OOPS....
Ans- OOPS stands for Object oriented programming system which communicates with object. Some of the languages which follows oops concept is Java,C++,LISP .
Concept under OOPS includes A-PIE i.e Abstraction, Polymorphism, Inheritance and Encapsulation.
Abstraction is a way to hide the implementation details and showing only the essential features of a method . in java abstraction can be achieved using abstract class and interface.
Polymorphism is the ability to have more than one form or using object in more than one way. Best example of polymorphism is + operator which can be used as string concatenation as well for adding 2 operands. In java there are 2 kinds of polymorphism: Run time-Method Overriding and Compile time-Method Overloading.
In case of method overriding a method in subclass overrides the method properties of the superclass. In overriding a method in subclass must have same argument list, it must have same return type or subtype of return type of superclass. it must have same access modifier or less restrictive than superclass method and finally a override method should not throw the new or broader checked exception compare to overridden method.
In case of method overloading a method in subclass must have different argument list, it can have different return type and can have different access modifier.Also it can throw broader checked exception.
Inheritance is a process by which a subclass inherits the properties of its superclass by accessing the variables or methods of the superclass. there are 3 types of inheritance, Single inheritance which is achieved by using extends keyword. Multiple inheritance is not supported directly by java but it can be achieved using interface as 1 class can implement more than 1 interface.
Inheritance provides code reusability.
Encapsulation is defined as wrapping up of data and method together, the best example of encapsulation is java class which have variables and method implementing those variables.
This flow you have to maintain for answering OOPS concept.
Hope you find it useful. BYE BYE......................