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

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

Moderator: admin

Post Reply
Deepa

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

Post by Deepa »

Hi Guys,

Just wanted to know, Whether subclass has to override the non abstract methods of the abstract class?

Please advise!

Thanks!

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

dmcinnis1
Posts: 16
Joined: Wed Feb 25, 2015 8:52 pm
Contact:

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

Post by dmcinnis1 »

Hi,

In the second option, should the explanation say "increased" access instead of "decreased access?

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

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

Post by admin »

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.

vlezz94
Posts: 12
Joined: Wed Sep 28, 2016 6:31 am
Contact:

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

Post 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; } }

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

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

Post by admin »

What happened when you tried it out?
If you like our products and services, please help us by posting your review here.

JoaoSusano
Posts: 1
Joined: Wed Feb 01, 2017 2:04 pm
Contact:

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

Post 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?

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 208 guests