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

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

Moderator: admin

Post Reply
Javier
Posts: 66
Joined: Mon Feb 20, 2017 12:31 pm
Contact:

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

Post by Javier »

Hi!

I would like to know why is compiling and running without problem the statement:

b.f();// A has got f(), but the object is of type B.
If there is not method f() in the B class...

Why is running without problem??

Thank you!!

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

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

Post by admin »

If B is a subclass of A and if A has non private f() then B will inherit f(). Thus, there is no issue in calling b.f().
If you like our products and services, please help us by posting your review here.

smahale
Posts: 4
Joined: Sun Oct 29, 2017 7:30 pm
Contact:

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

Post by smahale »

In the given code,

public class C{
A a = new A();//1
A b = new B();//2
}

if we were to do System.out.println(a.i);
Would this now print 10, or would it be a compile error?

Thanks!

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

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

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.

burlacu.valeri
Posts: 8
Joined: Tue Jan 26, 2021 7:55 am
Contact:

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

Post by burlacu.valeri »

Hi,

public void f(){}

why b.f( ) is compile error?

For me, it works without errors ... :/

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

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

Post by admin »

burlacu.valeri wrote:
Thu Feb 25, 2021 2:24 am
Hi,

public void f(){}

why b.f( ) is compile error?

For me, it works without errors ... :/
It is not a compile error that is why this option is not correct. Option 5, "None of the above statements is correct", is the correct option.
If you like our products and services, please help us by posting your review here.

burlacu.valeri
Posts: 8
Joined: Tue Jan 26, 2021 7:55 am
Contact:

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

Post by burlacu.valeri »

Hi,

ok, now I have understood. ;)

Post Reply

Who is online

Users browsing this forum: No registered users and 94 guests