- bunch of variables and methods that can be used to create other classes
- you cannot instantiate an abstract class like a regular class because an abstract class helps you make regular classes that can inherit the abstract class, and only then can we use those functionality!
- abstract methods are the most important part! abstract method is a method that is not implemented yet (meaning no code inside the curly braces)
- syntax is the same as other methods except we add keywords abstract
- so now when your class extends the abstract class, it can’t just invoke the abstract methods unless your class provides its own implementation of it!
- your class knows! it has to do that method, but it has no idea what to do because you haven't implemented, and that is what an abstract method is! you have to have it but dk what to do
- well in that case you can just remove your abstract method and say why do I even need this extra step and this abstract method in the first place if its just going to make more steps for me ?
- abstract classes help us organize what our classes should have, so we can just list out and make 100% sure that every single instance of a class has to have this method . like every dog has to have this method, but we make it abstract bc each specific object can do it a bit differently !
- this differs from an interface in that interface is just a list of methods and fields your class must have! notice that we dont have to use abstract keyword for an interface, and an interface assumes everything you list will be abstract (meaning unimplemented). I f we were to try to implement any default method in an interface, it would not work since an interface assumes that all methods are abstract meaning not implemented meaning there is no code in the body!
- but abstract class differs in that you can have a list of methods AND ones that are already implemented
- do code examples (use Animal Example w/ makeSound )
- can declared type be abstract class? (yes in slides)!
Inheritance is for inheriting properties and having some of its own as well. (like different people in a university, students employees etc we all inherit the ID property, name etc)
Abstract is to restrict from being instantiated.
It is just to restrict its instantiation. Eg. We don't want to instantiate Vehicle object because there is no meaning to it. A vehicle has to be something like car, bus etc etc. It can't just be a vehicle. So we put abstract and restrict instantiation.