You are on page 1of 4

Board

/g/ - Technology ▼ Settings Home

Return Catalog Bottom Refresh

Thread archived.
You cannot reply anymore.

Anonymous 05/14/18(Mon)14:40:36 No.65936905


Java abstract and interfaces

Why are interfaces and abstract so hard to understand?

105 KB PNG

Anonymous 05/14/18(Mon)14:41:38 No.65936916

>>65936905
Because you are a brainlet

Anonymous 05/14/18(Mon)14:45:34 No.65936969

>>65936916
I have a math phD you can't call me a brainlet.

Anonymous 05/14/18(Mon)14:50:56 No.65937045

>>65936969
Okay, but that doesn't change the fact that you're a brainlet.

Anonymous 05/14/18(Mon)14:52:40 No.65937067

>>65936905
They are piss easy to understand if you have a triple-digit IQ.

Anonymous 05/14/18(Mon)14:53:28 No.65937076

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

Anonymous 05/14/18(Mon)14:54:31 No.65937097

>>65936905
Abstract classes and interfaces are an abstraction for type based switch cases.

Anonymous 05/14/18(Mon)14:57:12 No.65937125

>>65937097
>type based switch cases.
This has absolutely nothing to do with type based switch cases.

Anonymous 05/14/18(Mon)14:59:50 No.65937160

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

Anonymous 05/14/18(Mon)15:12:59 No.65937316

>>65937125
Yes it does.

Anonymous 05/14/18(Mon)15:13:48 No.65937332

>>65937160

18 KB JPG

Anonymous 05/14/18(Mon)15:15:27 No.65937359

A class is like a struct with functions.

With an abstract class you don't know yet how big the "struct" is so you can't make it.

That's how I see it.

Anonymous 05/14/18(Mon)15:15:54 No.65937366

>>65936905
Learn Smalltalk.

Anonymous 05/14/18(Mon)15:23:57 No.65937485

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

Why even bother adding abstract...


abstract class A
{
abstract int add(int a, int b
);
}

abstract class B extends A


{

Anonymous 05/14/18(Mon)15:27:51 No.65937524

>>65936905
https://docs.oracle.com/javase/tutorial/java/IandI/abstract.html
https://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html

Anonymous 05/14/18(Mon)15:48:08 No.65937779

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

Anonymous 05/14/18(Mon)15:50:41 No.65937811

>>65936905
because they are redundant and people's logic rebels against illogic

Anonymous 05/14/18(Mon)15:57:48 No.65937889

>>65936905
All of that shit is obvious if you understand inheritance.

Anonymous 05/14/18(Mon)16:02:25 No.65937941

>>65937889
so inheritance is hard.

Anonymous 05/14/18(Mon)16:08:12 No.65938016

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

That's pretty much it.

Anonymous 05/14/18(Mon)16:13:23 No.65938069

>>65936905
well,your brain is a little bit slow thats all.

Anonymous 05/14/18(Mon)16:14:30 No.65938083

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

Return Catalog Top Refresh

[Disable Mobile View / Use Desktop Site]

About • Feedbac k • Legal • Contac t

You might also like