About Question enthuware.ocajp.i.v7.2.1217 :
Moderator: admin
About Question enthuware.ocajp.i.v7.2.1217 :
Hi Guys,
Just wanted to know, Whether subclass has to override the non abstract methods of the abstract class?
Please advise!
Thanks!
Just wanted to know, Whether subclass has to override the non abstract methods of the abstract class?
Please advise!
Thanks!
-
- Site Admin
- Posts: 10067
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1217 :
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.
The subclass must override the abstract methods of the superclass only if the subclass is not abstract itself.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 16
- Joined: Wed Feb 25, 2015 8:52 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1217 :
Hi,
In the second option, should the explanation say "increased" access instead of "decreased access?
In the second option, should the explanation say "increased" access instead of "decreased access?
-
- Site Admin
- Posts: 10067
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1217 :
No, it is correct. default makes a method less accessible than protected.
If you like our products and services, please help us by posting your review here.
-
- Posts: 12
- Joined: Wed Sep 28, 2016 6:31 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1217 :
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:
To get something like this:
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; } }
Code: Select all
abstract class A{ protected int m1(){ return 0; } } class B extends A{ public int m1(){ return 1; } }
-
- Site Admin
- Posts: 10067
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1217 :
What happened when you tried it out?
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Wed Feb 01, 2017 2:04 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1217 :
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?
Maybe
abstract public class A(){}
?
Or am I confused with something?
-
- Site Admin
- Posts: 10067
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1217 :
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.
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.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot] and 202 guests