About Question enthuware.ocajp.i.v7.2.990 :
Moderator: admin
-
- Posts: 78
- Joined: Sun Jun 30, 2013 10:04 pm
- Contact:
About Question enthuware.ocajp.i.v7.2.990 :
I answered this question using the compiler and answered it correctly.
Now looking at the question again it is not clear to me what the question is asking for.
Which of the following methods can be inserted at line //1 ?
It is an "open ended" question so you do not know whether you should use
1) overriding or
2) overloading?
When one looks at all the available options,
option e) public abstract void teach(String s)
is the only one that is abstract.
Is this the property or characteristic that prevents one from inserting this method
at line //1?
Now looking at the question again it is not clear to me what the question is asking for.
Which of the following methods can be inserted at line //1 ?
It is an "open ended" question so you do not know whether you should use
1) overriding or
2) overloading?
When one looks at all the available options,
option e) public abstract void teach(String s)
is the only one that is abstract.
Is this the property or characteristic that prevents one from inserting this method
at line //1?
-
- Site Admin
- Posts: 10114
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.990 :
Hi,
The explanation for this option says, "This is wrong because class Prof has not been declared as abstract. Note that otherwise it is OK to override a method by an abstract method."
You cannot have an abstract method in a non-abstract class.
HTH,
Paul.
The explanation for this option says, "This is wrong because class Prof has not been declared as abstract. Note that otherwise it is OK to override a method by an abstract method."
You cannot have an abstract method in a non-abstract class.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 37
- Joined: Thu Feb 13, 2014 12:58 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.990 :
The question asked "Which of the following methods can be inserted at line //1" I assumed which option at a time not all together, so just C & D are correct, but if the question asked "Which of the following methods can be inserted in Prof class with other methods" A & B & C & D were correct. did I get wrong?
-
- Site Admin
- Posts: 10114
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.990 :
Why do you think A and B are wrong if inserted independently(i.e.without any other method) as you said?
If you like our products and services, please help us by posting your review here.
-
- Posts: 37
- Joined: Thu Feb 13, 2014 12:58 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.990 :
Oh :O
I got it
I just assumed it should be just overriding, but it could be another method independently from super class method, my bad.
your question helped me to realize my fault, thank you.
I got it
I just assumed it should be just overriding, but it could be another method independently from super class method, my bad.
your question helped me to realize my fault, thank you.
-
- Posts: 42
- Joined: Mon Jan 20, 2014 2:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.990 :
So lets just try to put fasty32 question and answer clear.
fasty32 had found it hard at the beginning to realize that the act of overloading
can be made actually from the extended class, and still will be treated by the compiler as overloading and not overriding. A fact that I myself find hard to realize.
true || false ?
fasty32 had found it hard at the beginning to realize that the act of overloading
can be made actually from the extended class, and still will be treated by the compiler as overloading and not overriding. A fact that I myself find hard to realize.
true || false ?
-
- Site Admin
- Posts: 10114
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.990 :
Overloading is very very different from overriding. Overloading is basically same as having another method altogether. For example, if base class has a method named m1(), can a subclass have a method named m2? Of course, yes. Would you say that m2 overrides m1? Of course not. Technically, it is the same with overloaded methods. For example, m1(int) and m1(int, int) are exactly same has having m1() and m2(). They are different methods with no relation at all.
If you like our products and services, please help us by posting your review here.
-
- Posts: 42
- Joined: Mon Jan 20, 2014 2:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.990 :
Thanks for making things clear.. actually I've checked the KS&BB guide and I've found out
the following facts:
in chapter 2 page 110 it says:
the KS&BB guide....
the following facts:
in chapter 2 page 110 it says:
And the "exam watch" paragraph in page 114 that says:■ A method can be overloaded in the same class or in a subclass. In other words,
if class A defines a doStuff(int i) method, the subclass B could define a
doStuff(String s) method without overriding the superclass version that
takes an int. So two methods with the same name but in different classes
can still be considered overloaded, if the subclass inherits one version of the
method and then declares another overloaded version in its class definition.
So thanks for waking me up and "Forcing" me (few weeks ago though) to read thoroughlyDon’t be fooled by a method that’s overloaded but not overridden by a
subclass. It’s perfectly legal to do the following:
public class Foo {
void doStuff() { }
}
class Bar extends Foo {
void doStuff(String s) { }
}
The Bar class has two doStuff() methods: the no-arg version it inherits
from Foo (and does not override), and the overloaded doStuff(String s) defined in the
Bar class. Code with a reference to a Foo can invoke only the no-arg version, but code
with a reference to a Bar can invoke either of the overloaded versions.
the KS&BB guide....
-
- Posts: 9
- Joined: Mon Jun 28, 2021 4:50 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.990 :
Please tell me. I answered correct when I saw abstract method. But really I saw that no one method is correct, because every methods don't have own body of method! Because Class Prof is not abstract class.
-
- Site Admin
- Posts: 10114
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.990 :
None of the methods has a body because the question is about the method signature only, which is clear from the fact that there are 4 correct options and there is no option that says "none of the above is correct".
Also, only one method has abstract keyword. So, only that one is abstract. Others are concrete methods.
Also, only one method has abstract keyword. So, only that one is abstract. Others are concrete methods.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 14 guests