+ 2
Difference between Abstract and protected?
List the rules of abstraction if possible.
10 Antworten
+ 7
Think of a Zoo. There are many different animals. So we define an abstract class animal. This contains an attribute "legs" and a method "action" which prints out the sound the animal does. Cause animals have a different number of legs and do different noises you dont wanna implement them hard. So you define a class Lion which inherits Animal. Then you can override legs with a value of 4 and your action method by printing "Roar" in it. This you can do for all kind of animal.
+ 5
Abstract classes cant be instantiated so they cant create any kind of methods or variables they are a blueprint for other classes
+ 3
Abstract class are useful if you want to use an Array of Animal (regardless what type of animal) (to use @AKC's zoo) for example
You can also use them for the use of someone else. For example you code a library of graphic display (yeah your good) and you want to create a pattern so that programmers will be able to create their own object, you can use an abstract class for it
+ 2
I dont list rules of abstraction, because your question targets two completely different things. Abstract is a programming concept to create a pattern for other classes. protected is an access modifier like public and private. protected variables can be accessed from all classes in your package.
+ 2
what's the point of using abstract in real life coding? Just for setting a pattern? why?
+ 2
Abstract is used for polimorfism (polimorfismo I dont know english, sorry). Protected is a encapsulation (cláusula de encapsulación, de acceso) or access clause.. the a class
+ 1
@Baptiste I like that you built on others answers to expand yours. :)
+ 1
abstract and protected are two different things
abstact class or method can't be instanciated
however a protected class or method is visible just in the same package
+ 1
an abstract class is interface
- 7
Hvfhnbv