About Question enthuware.ocajp.i.v7.2.1220 :
Moderator: admin
-
- Posts: 66
- Joined: Mon Feb 20, 2017 12:31 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1220 :
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!!
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!!
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1220 :
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.
-
- Posts: 4
- Joined: Sun Oct 29, 2017 7:30 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1220 :
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!
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!
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1220 :
What happened when you tried it out?
If you like our products and services, please help us by posting your review here.
-
- Posts: 8
- Joined: Tue Jan 26, 2021 7:55 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1220 :
Hi,
public void f(){}
why b.f( ) is compile error?
For me, it works without errors ... :/
public void f(){}
why b.f( ) is compile error?
For me, it works without errors ... :/
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1220 :
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.burlacu.valeri wrote: ↑Thu Feb 25, 2021 2:24 amHi,
public void f(){}
why b.f( ) is compile error?
For me, it works without errors ... :/
If you like our products and services, please help us by posting your review here.
-
- Posts: 8
- Joined: Tue Jan 26, 2021 7:55 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1220 :
Hi,
ok, now I have understood.
ok, now I have understood.
Who is online
Users browsing this forum: No registered users and 53 guests