Qus:    Can we declare the static variables and methods in an abstract class?
Mar 20, 2022 16:05 Java 1 Answers Views: 1349 Anju
Prev Next
Answers (1)
dawn vfahy Feb 22, 2021 15: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 solution is right for you?

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


Let`s Connect