Object Oriented Programming basically depends on the some of oops concepts. Mostly questions asked on this. You feel really frustated when u didn't able to answer to this kind of questions. Interview don't want a simple explanation from u instead have you understand the concepts really well ? So i m here don't explain real definition.
I got cleared almost all tech interviews becoz i got faced simple questions like encapsulation, star pattern, fibonacci series with recursion, simple questions. If you have some interest in programming and as well as good communication skill then surely world will be in your hand. Be prepare with gud communication skill, friends, it matters a lot. I m not got placed till now becoz poor communication skill and nervousness in hr interview.
Lets start -
What is encapsulation ?
Wrapping up of data into a single unit is encapsulation. In encapsulation what we do. We declare all instance variables private and all member functions public. We can get and set value through the public member functions. So by declaring instance variables private it can't be access outside class directly.
In java encapsulation is
all instance variables r private like private String name.
all setter and getter methods r public public setName(String opopop), public String getName().
What is polymorphism ?
One interface in many forms thats simple. Functions overloading and overiding performs this task. Overloading means a function or constructor with different types or no. of arguments. You should be aware only change in return types not called overloading.
Overiding means a function with same name in base and derived calls both. Only though inheritance we can do overiding. We can restrict it with using final keyword before function.
class A{
public void oldFunction(){
//any code
}
public void oldFunction2(){
}
//any code
}
class B extends A
{
public void oldFunction1(){
// any code
}
public static void main(String args[])
{
A a = new B();
a.function(); // calls class A function().
/* At compile time compiler sees only reference a functions and at runtime it overides all functions which present in class A. All functions declare in class B must be present in class A. Otherwise it will show error. So be careful.
Now what is use of this ?
Suppose we have some functionality in old project now we want to add new functionality and don't want to change old codes. What can we do create a subclass overide the function which we want to change. Now call that function with class A reference. Now you r free to use both functions with single object.
Now when we call oldFunction1() it would call subclass function. Thats huge benefit! only with single object we can use both projects codes.
}
}
What is inheritance ?
Inheritance is capabilites of subclass to extends properties of superclass. AcessSpecifiers r three types : private, protected and public. By declaring private we restrict members for inheritance. We use extends keyword for inherit class.
Java doesn't support multiple inheritance bt not in case of interface.
What is abstration ?
Abstration is hiding the unnecessary details. It is part of encapsulation. Declaring instance variables private is abstration.
Abstract class also provides abstration. Abstract class not defines any functions.
Home »
» basic oops concepts in any programming language
basic oops concepts in any programming language
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment