A teacher gave me this lecture with some questions, and I am somewhat confused.
Say we have a hierarchy like:
Object
|
+---A
|
+---B
|
+---C
and we made these methods in Class A:
public abstract void method1();
public abstract void method2(int i);
so... these questions were presented to us:
(a) If class B does not override any of the two methods above, can class B be compiled cleanly? If so, can an object be created from class B? If not, explain why not.
(b) Now assume that class B overrides method1 given above. Can class B be compiled cleanly? If so, can an object be created from class B? If not, explain why not.
(d) In defining class A described above, must the abstract modifier be used in the 1st line of the class definition (or is it optional given that it has abstract method(s) in it)?
(e) In defining method1 and method2 described above, must the abstract modifier be used in the method statement (or is it optional given that it has no method body)?
Ok, so if a subclass, which would be B, doesn't override the abstract methods, it becomes an abstract class, correct? But I'm not really sure if it can create an object or not, I don't believe it can, but can someone at least elaborate on this.
Question
LRoling
A teacher gave me this lecture with some questions, and I am somewhat confused.
Say we have a hierarchy like:
Object
|
+---A
|
+---B
|
+---C
and we made these methods in Class A:
public abstract void method1();
public abstract void method2(int i);
so... these questions were presented to us:
(a) If class B does not override any of the two methods above, can class B be compiled cleanly? If so, can an object be created from class B? If not, explain why not.
(b) Now assume that class B overrides method1 given above. Can class B be compiled cleanly? If so, can an object be created from class B? If not, explain why not.
© Now assume that class C overrides method2 given above (with the assumption that B overrides method1, as discussed in part(b)). Can class C be compiled cleanly? If so, can an object be created from class C? If not, explain why not.
(d) In defining class A described above, must the abstract modifier be used in the 1st line of the class definition (or is it optional given that it has abstract method(s) in it)?
(e) In defining method1 and method2 described above, must the abstract modifier be used in the method statement (or is it optional given that it has no method body)?
Ok, so if a subclass, which would be B, doesn't override the abstract methods, it becomes an abstract class, correct? But I'm not really sure if it can create an object or not, I don't believe it can, but can someone at least elaborate on this.
Any help would be appreciated.
Link to comment
Share on other sites
7 answers to this question
Recommended Posts