+ 12
What is a difference between static and abstract functions /classes?
6 Respostas
+ 8
An abstract class is that which must be extended. If you use abstract method in a class then that means the class is abstract also so you have to declare that class as abstract. Abstract class behaves as a template. Abstract class can contain static data. Abstract class can not be instantiated
While
Static class is that whose methods and variables can be called without creating the instance of the class. Static means which is initialized once for example our main method is initialized only once.
+ 2
an abstract class is that which can have one or more than one abstract methods.abstract methods are those which don't have implementation/body rather only has its declaration.it will necessarily have abstract keyword.Abstract class is used so that we can provide abstraction I.e can hide implementation and leave it on its child class...we can't instantiate our abstract class.all variables inside abstract class must be static.
and, static is a keyword which makes any variable or method a class level variable or class level method ,means we can access it by our class name without making object of class.
+ 1
an abstract class needs to have a abstract method to extend in derived class but static members can be called anywhere without making object these are global
+ 1
abstract class dont have a behaviour so we cant able to instantiate it.
- 1
There are abstract and static methods but there is no such kind of static class.
And moreover which class contains at least one abstract method, then that will be called as abstract class..
You can call static members instead of static class.. the class can contains static variables, static methods, static blocks.. but "static" keyword is not applicable for class.
Instead of this question you can search for Static Vs Instance members...
I hope this answer will helps your question😊
- 2
Nelli ur very smart and beautiful girl