#Simple question

1 messages · Page 1 of 1 (latest)

tropic narwhal
#

What types of objects can the ArrayList list of the Main class contain?

  1. InterfaceA

  2. ClassA, ClassB, ClassC, ClassD and InterfaceA

  3. ClassA, ClassB, ClassC and ClassD

  4. ClassB, ClassC and Class D

  5. ClassB, ClassD and InterfaceA

  6. ClassB and Class D

void ploverBOT
#

<@&987246399047479336> please have a look, thanks.

tropic narwhal
#

I think the answer is option 4, I am not 100% sure though

misty bone
#

the list requires InterfaceA objects

#

is ClassA an InterfaceA?

tropic narwhal
#

No

misty bone
#

correct, is ClassB an InterfaceA?

#

thats how you can determine

tropic narwhal
#

Yes, and so is classC and classD?

misty bone
#

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?

tropic narwhal
#

I think it's between 4 and 6, classC is confusing me

#

it is still inheriting classB which is an interfaceA?

misty bone
#

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

tropic narwhal
#

Ah, i see

misty bone
tropic narwhal
#

and you can't have objects of interfaces either

#

making 4. correct?

misty bone
#

nope. you can create anonymous classes to instantiate, but those anonymous classes are technically subtypes

#

where are you getting 4 from?

tropic narwhal
#

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?

tropic narwhal
#

hello?

tropic narwhal
burnt goblet
#

og means or?

tropic narwhal
#

it means and

#

my bad, forgot to translate that

#

I did it now :p

misty bone
#

not 4

tropic narwhal
#

4 is classC, classB and classD

misty bone
#

C, B, and D would be 3

#

ohhh

burnt goblet
#

put down the bottle

#

Why do you think 5 wouldn't also be an answer?

tropic narwhal
#

because you can't have objects of interfaces?

#

so interfaceA can't be one of the answers

burnt goblet
#

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.

tropic narwhal
#

It was a single answer

misty bone
misty bone
#

my bad

plucky gate
#

the question asks what type the arraylist can contain, and it very well can contain objects of the type InterfaceA

tropic narwhal
plucky gate
#

all objects of type ClassB are of type InterfaceA too

misty bone
#

since InterfaceA cant be instantiated, shouldnt consider it an object

plucky gate
#

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

latent spindle
#

Is there any background to this question or related topics? It seems a bit ambiguous, and perhaps different people might have different... interpretations?

misty bone
#

but ClassB and ClassC can be instantiated. InterfaceA can't be

#

so unless it's a trick question..

tropic narwhal
burnt goblet
#

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.

misty bone
#

yes, it's assumed all types of InterfaceA are supported. but it seems they're asking about objects

#

"what types of objects"

burnt goblet
#

If you want points with the prof then just ask to clarify the second condition I stated is also what he meant.

plucky gate
#

how to you define the type of an object then

misty bone
plucky gate
#

by LSP an object can have multiple types, its direct class and all its parents

misty bone
#

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"

plucky gate
#

My point is, if the subtype can replace the supertype then the type of the instance is both the subtype and supertype

latent spindle
#

This seems unrelated to LSP; it's a bit of a stretch.

plucky gate
#

It can only be used where the supertype is needed, if and only if it is of that type

plucky gate
misty bone
#

i think it boils down to "types of objects"

#

i can see what spanish is implying

plucky gate
plucky gate
latent spindle
#

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.

misty bone
#

there is no "B, C, D, InterfaceA" option

#

if there was, what spanish is saying would make sense, should ask for clarification

plucky gate
misty bone
#

this doesnt seem to be about generic type erasure though

#

process of elimination

plucky gate
#

I meant it occurs after type checking, sorry I should have been specefic

misty bone
#

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

tropic narwhal
#

What variables and/or methods are available through the variable in the Main class?

Choose one option:

  1. weight, cute og pet()

  2. pet()

  3. weight og pet()

  4. weight

  5. 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."

misty bone
#

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

misty bone
#

as for #1, that depends on the packaging

burnt goblet
#

It's just pet and weight.

#

It's protected not package private

misty bone
misty bone
burnt goblet
#

That's new to me.

misty bone
#

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

tropic narwhal
misty bone
tropic narwhal
#

weight is public, so it should be accessable, and cute is protected, and dog extends animal so that one should be accessable too?

misty bone
#

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

tropic narwhal
#

"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"

misty bone
#

if they are in different packages, then it wouldnt be accessible

#

oh alright, my bad

#

then yeah

tropic narwhal
#

that's the only information i got besides what i sent

misty bone
#

cute wouldnt be accessible, because "contained in separate packages"

#

i did overlook that

tropic narwhal
#

cute isn't accessable?

misty bone
#

look into protected

tropic narwhal
#

but dog extends Animal

burnt goblet
#

What is the benefit of protected if it is also package private?

misty bone
#

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

misty bone
#

tbh, i didnt dive into why they implemented protected that way, because i stay away from protected