0

What is the use of extend () ?????

It is said something related to class

30th Sep 2016, 5:12 PM
Aditya
Aditya - avatar
2 Respuestas
0
as per my knowledge, I didn't see any extend() method in java. but there is a keyword "extends" in java used to inherits variables and methods from super class to sub class. refer inheritance concept.
30th Sep 2016, 5:51 PM
Vaibhav Kharche
Vaibhav Kharche - avatar
0
sure man, super class is nothing but a parent class from which we are deriving our child class with extended functionality. when we extends a class from super class, then all members (other than private) available in sub class. all members means may be variables or methods. see follow example: class Parent{ void add(int num1, int num2){ System.out.println("sum is: "+ num1+num2); } } class Child extends Parent{ public static void main(String[] args){ Child c = new Child(); c.add(10,20); } } now note that in above two classes Parent class is super class and Child class is sub class (i.e. sub class of parent). now see that in Parent class I have created add() method with two int parameters, in Child class i have call that method using Child class object. i.e. I am calling the add() method defined in Parent class directly from our Child class using our Child class object. hope you uderstand... right back if any confusion :)
30th Sep 2016, 6:59 PM
Vaibhav Kharche
Vaibhav Kharche - avatar