Which of the following lines of code that, when inserted at line 1, will make the overriding method in SubClass invoke the overridden method in BaseClass on the current object with the same parameter.
class BaseClass{
public void print(String s) { System.out.println("BaseClass :"+s); }
}
class SubClass extends BaseClass{
public void print(String s){
System.out.println("SubClass :"+s);
super.print(s);
}
public static void main(String args[]){
SubClass sc = new SubClass();
sc.print("location");
}
}
//How come super statement being right here even though it isnt the first line of the constructor?
About Question enthuware.ocajp.i.v7.2.952 :
Moderator: admin
-
- Posts: 7
- Joined: Thu Mar 30, 2017 7:15 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.952 :
Only the call to super class's constructor need to be the first statement. The syntax for that is super(<params>). You can use super dot syntax to call a method of the super class anywhere.
Who is online
Users browsing this forum: No registered users and 11 guests