+ 1

What does the keyword super meaning in java

java

1st Jul 2017, 5:31 PM
Syedali Fathima
Syedali Fathima - avatar
7 Respostas
+ 1
Basically is a reference pinter to members in super or parent class of present class... Reference variable that is kind of dependent on relationship... Like this refers to same class super refers to super class
1st Jul 2017, 5:53 PM
Anshul Garg
Anshul Garg - avatar
+ 2
Sure, but in my opinion that's just messy :p , if you need certain functionality in a subclass it doesn't make sense to call it from the parent, the function should be in the parent class to begin with
1st Jul 2017, 6:04 PM
Jared
Jared - avatar
+ 1
super refers to the parent class of the class you're currently in For example, if you create a child class based on parent, you can call the parent constructor from within the child class using values passed to the constructor of the child class class Parent { private int value; Parent(int param){ this.value = param; } } class Child extends Parent { Child(int param){ super(param); } } In this example, you can set value of the parent class using super without having to make value protected. Also, you'll be able to call any private methods of the parent class using super.[methodname]()
1st Jul 2017, 5:36 PM
Jared
Jared - avatar
+ 1
For that case we could have exceptions na... Java has a whole lot of exception handling ..
1st Jul 2017, 6:00 PM
Anshul Garg
Anshul Garg - avatar
+ 1
Kind of pro answer man... Thanks
1st Jul 2017, 6:06 PM
Anshul Garg
Anshul Garg - avatar
0
Hey can anyone answer what ref variable we use for calling members of sub class from present class... Super is for parent... This is for preset... Then what do we use for sub class...??
1st Jul 2017, 5:55 PM
Anshul Garg
Anshul Garg - avatar
0
I don't believe that exists just because that could lead to some problems like if that subclass doesn't exist, it's more organized to only have to keep track of class hierarchies by referring to the parent class
1st Jul 2017, 5:58 PM
Jared
Jared - avatar