#Simple question
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
I think the answer is option 4, I am not 100% sure though
think in terms of "is a"
the list requires InterfaceA objects
is ClassA an InterfaceA?
No
Yes, and so is classC and classD?
ClassB is an InterfaceA, and a ClassC is a ClassB
so ClassC inherits the type of being an InterfaceA
ClassD implemente InterfaceA directly
so with all that info in mind, what do you think the answer is?
I think it's between 4 and 6, classC is confusing me
it is still inheriting classB which is an interfaceA?
is what still inheriting ClassB?
oh, yes
ClassC extends ClassB
which means "ClassC is a ClassB"
and since "ClassB is a InterfaceA"
that means ClassC must also be an InterfaceA, since
ClassC is a ClassB
ClassB is a InterfaceA
its a hierarchy
if a supertype is something, the subtype is also that
Ah, i see
nope. you can create anonymous classes to instantiate, but those anonymous classes are technically subtypes
where are you getting 4 from?
like you said, classC is a classB, classB is a interfaceA and classD is a interfaceA
so classC, classB and classD are the correct options?
isn't that right?
hello?
sure
thanks, but why wasn't he agreeing with me lol
og means or?
3 is classA, classB, classC and classD
4 is classC, classB and classD
because you can't have objects of interfaces?
so interfaceA can't be one of the answers
It's a bit subjective as to their meaning perhaps. If they are looking for a single answer, then 4 fits best. If they're looking for multiple answer AND are implying anything implementing InterfaceA, then 5 is also an answer.
It was a single answer
cant instantiate an interface, an anonymous class would be a subtype. so unless InterfaceA is a functional type & lambdas are considered valid, InterfaceA shouldn't be considered a valid value
the question asks what type the arraylist can contain, and it very well can contain objects of the type InterfaceA
haha, maybe i should've been clearer by saying "option 4" instead too :p
all objects of type ClassB are of type InterfaceA too
what types of objects
since InterfaceA cant be instantiated, shouldnt consider it an object
it is ambigous, so between 4 and 5 I would pick 4
Agreed, but the objects of its child classes are its objects too
that is the reason why the ArrayList can contain objects of ClassB and ClassC
Is there any background to this question or related topics? It seems a bit ambiguous, and perhaps different people might have different... interpretations?
but ClassB and ClassC can be instantiated. InterfaceA can't be
so unless it's a trick question..
only this:
"This task is based on the code in the included PDF. You should interpret the content to mean that all classes had been contained in separate files and packages"
It's rather pointless to argue this meta further. Professors are not automatons. No where is it specified multiple, additive or exclusive answers are valid.
yes, it's assumed all types of InterfaceA are supported. but it seems they're asking about objects
"what types of objects"
If you want points with the prof then just ask to clarify the second condition I stated is also what he meant.
how to you define the type of an object then
well to begin, there has to be an object
by LSP an object can have multiple types, its direct class and all its parents
an object having multiple types has nothing to do with LSP
LSP is about contract violations
when a subtype violates the contract of the supertype, breaking the "can replace all instances of supertypes with instances of subtypes without breaking expected behavior"
My point is, if the subtype can replace the supertype then the type of the instance is both the subtype and supertype
This seems unrelated to LSP; it's a bit of a stretch.
It can only be used where the supertype is needed, if and only if it is of that type
Like I said, a safer option is 4
but if you can have multiple answers, there can be confusion
Yes at the end it is down to your professor's interpretation, when ur grade is concerned
Is it possible that this is all a diversion, and they actually want to discuss Java generic type erasure? So, in essence... I feel like without more specific requirements, it might not make much sense.
there is no "B, C, D, InterfaceA" option
if there was, what spanish is saying would make sense, should ask for clarification
I don't think that is relevant, erasure does not occur at compile time
erasure does occur at compile time
this doesnt seem to be about generic type erasure though
process of elimination
I meant it occurs after type checking, sorry I should have been specefic
pretty sure we can all agree B, C, and D are the supported types
the only other challenge to that would be including InterfaceA, but that's not an option
What variables and/or methods are available through the variable in the Main class?
Choose one option:
-
weight, cute og pet()
-
pet()
-
weight og pet()
-
weight
-
cute
and this one? alternative 1. should be correct?
the commented out lines say "We assume that the class contains what is necessary to follow inheritance and implementation, based on the class definition above."
"alternative 1"?
it depends on which package Animal and Main are in
so that's a pretty poor question
the key here is protected
if Main is in the same package, can access it. otherwise, if Main was in a different package, can't access it
@burnt goblet if you thought the last question was ambiguous, check this one out
not sure if im reading it properly
this one seems ambiguous based on the packaging, which isn't shown in the question
seems like a "process of elimination" to determine
try to determine if answers 2, 3, 4, or 5 can possibly be correct
as for #1, that depends on the packaging
what about cute if Main & Animal are in the same package?
protected has package-private behavior too
That's new to me.
but you see now where this question becomes ambiguous, yeah? i didnt overlook anything?
dont think this can be answered without knowing which packages the classes are in
Alternative 1 as in weight, pet() and cute
it depends on which packages those classes are in
weight is public, so it should be accessable, and cute is protected, and dog extends animal so that one should be accessable too?
if Main and Animal are in the same package, Main would be able to access the protected member
im not sure if your professor knows that
"This task is based on the code in the included PDF. You should interpret the content to mean that all classes had been contained in separate files and packages"
if they are in different packages, then it wouldnt be accessible
oh alright, my bad
then yeah
that's the only information i got besides what i sent
cute wouldnt be accessible, because "contained in separate packages"
i did overlook that
cute isn't accessable?
look into protected
but dog extends Animal
What is the benefit of protected if it is also package private?
yes, so Animal would have access. but Main isnt in the same package, or a subclass
protected is only accessible by subtypes or classes within the same package
it was probably implemented for helper types
tbh, i didnt dive into why they implemented protected that way, because i stay away from protected