Java Abstract and Interfaces
Java Abstract and Interfaces
Thread archived.
You cannot reply anymore.
105 KB PNG
>>65936905
Because you are a brainlet
>>65936916
I have a math phD you can't call me a brainlet.
>>65936969
Okay, but that doesn't change the fact that you're a brainlet.
>>65936905
They are piss easy to understand if you have a triple-digit IQ.
>>65937045
well if im a brainlet then why don't you explain it to me mr know it all
Anonymous 05/14/18(Mon)14:54:28 No.65937096
>>65936969
If you actually had a math PhD you'd be very comfortable with the idea of inheriting structure.
>>65936905
Abstract classes and interfaces are an abstraction for type based switch cases.
>>65937097
>type based switch cases.
This has absolutely nothing to do with type based switch cases.
>>65937076
Abstract Classes:
Rules:
• If a method is abstract then the class must be abstract
• If class is abstract, methods don't have to be abstract, but they usually are
• Abstract class: can't make an object of this class
• abstract method: Treats method like an interface (can't fill in body of method)
• Requires methods to be filled in in the sub-class
• You CAN have a constructor in an abstract class
• SubclassName extends abstractClassName
>>65937125
Yes it does.
>>65937160
18 KB JPG
With an abstract class you don't know yet how big the "struct" is so you can't make it.
>>65936905
Learn Smalltalk.
>>65937359
But that doesn't make sense to me.
If you want to write code, but don't yet know what to write, then just don't write it?
>>65936905
https://docs.oracle.com/javase/tutorial/java/IandI/abstract.html
https://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html
>>65937485
Speaking C++-wise here.
They are used as base classes for other classes to inherit from.
When you inherit from the abstract class, you MUST override all the pure virtual functions. ( if you want the class to be non-abstract )
I don't really use them all that much, but I guess they would be good for pajeets who make a new class and when you try and call
object->cleanup(); they have to have actually implemented it, otherwise it won't build.
>>65936905
because they are redundant and people's logic rebels against illogic
>>65936905
All of that shit is obvious if you understand inheritance.
>>65937889
so inheritance is hard.
>>65937076
Abstract class is just a prototype for a instantiated subclass. I.E. animal as an abstract class, there's no such thing as animal, but
animal defines behaviours that the instantiated subclasses should have. I.e. eat, shit, walk, etc. each subclass i.e. cat, dog etc. would
have their own unique implementation of these methods, and the abstract class enforces that by defining the abstract methods.
instantiated subclasses cannot have abstract methods because you're actually going to instantiate that class so nothing should be
abstract in it, an abstract class can have all real methods that as the sub class can inherit these and fall back on them if you decide to
not define said method or constructor in the sub class.
An interface is just what it says, an interface, think of one of those toys kids play with where you push the correctly shaped blocks
through the different size holes. The interface just holds both sides of a party to a common standard. So you design your method
headers before you start actually building component X which means you know what you have to produce for each part in component
X to match the interface, but also everyone else that is going to use component X knows how to call the functions on it.
>>65936905
well,your brain is a little bit slow thats all.
>>65938016
wow this is actually a really good explanation
holy shit
this was 10x better than anything my professors had ever explained to me
Anonymous 05/14/18(Mon)16:18:59 No.65938151
>>65938083
>this was 10x better than anything my professors had ever explained to me
there really exists an OOP class that doesn't use the animal/cat or a fruit/apple analogy to explain inheritance?
Post a Reply