Page 1 of 1
About Question enthuware.ocajp.i.v7.2.1217 :
Posted: Fri Feb 15, 2013 5:20 pm
by Deepa
Hi Guys,
Just wanted to know, Whether subclass has to override the non abstract methods of the abstract class?
Please advise!
Thanks!
Re: About Question enthuware.ocajp.i.v7.2.1217 :
Posted: Fri Feb 15, 2013 6:41 pm
by admin
No, it is not required to override a method that is already implemented by the super class even if the super class is abstract. It can do so, but not required.
The subclass must override the abstract methods of the superclass only if the subclass is not abstract itself.
HTH,
Paul.
Re: About Question enthuware.ocajp.i.v7.2.1217 :
Posted: Wed Mar 11, 2015 8:06 pm
by dmcinnis1
Hi,
In the second option, should the explanation say "increased" access instead of "decreased access?
Re: About Question enthuware.ocajp.i.v7.2.1217 :
Posted: Wed Mar 11, 2015 9:11 pm
by admin
No, it is correct. default makes a method less accessible than protected.
Re: About Question enthuware.ocajp.i.v7.2.1217 :
Posted: Mon Nov 07, 2016 7:15 pm
by vlezz94
Hi!
Just one simple question, in: enthuware.ocajp.i.v8.2.1217 // I read: "The concept here is that an overriding method cannot make the overridden method more private.". But can I make it less private?
Original:
Code: Select all
abstract class A{ protected int m1(){ return 0; } } class B extends A{ int m1(){ return 1; } }
To get something like this:
Code: Select all
abstract class A{ protected int m1(){ return 0; } } class B extends A{ public int m1(){ return 1; } }
Re: About Question enthuware.ocajp.i.v7.2.1217 :
Posted: Mon Nov 07, 2016 9:02 pm
by admin
What happened when you tried it out?
Re: About Question enthuware.ocajp.i.v7.2.1217 :
Posted: Wed Feb 01, 2017 2:07 pm
by JoaoSusano
Well this may be a dumb question but, since the file is called A.java, doesn't A's class have to be declared as a public class?
Maybe
abstract public class A(){}
?
Or am I confused with something?
Re: About Question enthuware.ocajp.i.v7.2.1217 :
Posted: Wed Feb 01, 2017 9:40 pm
by admin
No, the rule is that a public class must be declared in a file with the same name.
A non-public class can reside in any file. So it is ok to have a non-public class in a file with the same name.