About Question enthuware.ocajp.i.v7.2.952 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Chandu
Posts: 7
Joined: Thu Mar 30, 2017 7:15 am
Contact:

About Question enthuware.ocajp.i.v7.2.952 :

Post by Chandu »

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?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.952 :

Post by admin »

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests