I am new to android but Still I did not understand what is extends in java.
-
2Please go through documentations. – Prashant Mar 17 '20 at 03:00
-
And don't completely change your question. Ask a new one, deleting the old one if it has no answers and no longer has relevance. – user207421 Mar 17 '20 at 04:07
1 Answers
Forget about programming for now (I will come later)
- Think about an animal, Let's say Tiger. It jumps, it runs, it eats, it sleeps...
- consider another animal cat. it also jumps, eats, sleeps,....
- they have some common things between them. these behaviors are common for animals. They are extending the common behavior from their ancestors.
Now come to the Programming world
Let's create those animals in Java. Every animals have some common things among them. right?
class Tiger {
float weight;
float height;
public void jump() {
System.out.println("hey, See the jump");
}
public void eat() {
System.out.println("Tiger is eating, don't disturb");
}
}
class Cat {
float weight;
float height;
public void jump() {
System.out.println("hey, See the jump");
}
public void eat() {
System.out.println("I can eat veg");
}
}
but in programming world, We should not repeat. (Repeating a code is a not good practice). you can see jump has common code between cat and tiger. eating is differentiating.
So we can tell put those common things inside a Super class Animal. and extending them to cat and tiger
class Animal {
float weight;
float height;
public void jump() {
System.out.println("hey, See the jump");
}
public void eat() {
}
}
class Tiger extends Animal{
//it has Animal's jump method
@Override
public void eat() {
System.out.println("Tiger is eating, don't disturb");
}
}
class Cat extends Animal{
//it has Animal's jump method
@Override
public void eat() {
System.out.println("I can eat veg");
}
}
In above code, we reused jump method and changed eat method for cat and tiger.
The process by which one class acquires the properties(data members) and functionalities(methods) of another class is called inheritance. The aim of inheritance is to provide the reusability of code so that a class has to write only the unique features and rest of the common properties and functionalities can be extended from the another class.
It is a concept of OOP. It is called Inheritance. Learn some concepts of inheritance here

- 2,169
- 3
- 17
- 30
-
I see I got it now thank you. This is the best explanation I ever see and Thank you so much right now I understand it better. Thank you – furkanayilmaz Mar 18 '20 at 06:19
-
-
I have one last question it is about something else. What is onCreateView I mean it is about layoutInflater I know inflaters but like where do we use it why don’t we just inflate the method. Like what is the point of the onCreateView – furkanayilmaz Mar 18 '20 at 19:55
-
1Hi there, The main use of this method is telling to fragment "Hey fragment, use this layout xml file for this fragment". onCreateView is calling inside fragments. You can specify which layout xml should be used by the fragments through returning the method of 'onCreateView .'return inflater.inflate(R.layout.your_fragment_layout), container, false);' Many fragments can use one layout. If you don't specify the layout inside this method, your fragment won't show anything. (Fragment will be empty and you can't show anything to users) – majurageerthan Mar 18 '20 at 20:09
-
Thank you I got it right now I see how important it it is to use the onCreateView – furkanayilmaz Mar 19 '20 at 00:45