+ 1
What does the keyword super meaning in java
java
7 Respuestas
+ 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
+ 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
+ 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]()
+ 1
For that case we could have exceptions na... Java has a whole lot of exception handling ..
+ 1
Kind of pro answer man... Thanks
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...??
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