Qus:    Can we declare the static variables and methods in an abstract class?
Feb 20, 2021 10:05 1 Answers Views: 40 SANJAY
Prev Next
Answers (1)
RANJIT Feb 22, 2021 09:59
Answer:   Yes, we can declare static variables and methods in an abstract method. As we know that there is no requirement to make the object to access the static context, therefore, we can access the static context declared inside the abstract class by using the name of the abstract class. Consider the following example.
1. abstract class Test
2. {
3. static int i = 102;
4. static void TestMethod()
5. {
6. System.out.println("hi !! I am good !!");
7. }
8. }
9. public class TestClass extends Test
10. {
11. public static void main (String args[])
12. {
13. Test.TestMethod();
14. System.out.println("i = "+Test.i);
15. }
16. }
Output
hi !! I am good !!
i = 102

Post Your Answer
Guest User

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect