0% found this document useful (0 votes)
3 views3 pages

Part 17

Uploaded by

Up ka sher king
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Part 17

Uploaded by

Up ka sher king
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

o An abstract keyword can only be used with class and method.

o An abstract class can contain constructors and sta c methods.

o If a class extends the abstract class, it must also implement at least one of the abstract
method.

o An abstract class can contain the main method and the final method.

o An abstract class can contain overloaded abstract methods.

o We can declare the local inner class as abstract.

o We can declare the abstract method with a throw clause.

AD

Examples of abstract Keyword

Example 1: Abstract class containing the abstract method

1. abstract class Vehicle

2. {

3. abstract void bike();

4.

5. }

6. class Honda extends Vehicle

7. {

8.

9. @Override

10. void bike() {

11. System.out.println("Bike is running");

12.

13. }

14.

15. }

16.

17. public class AbstractExample1 {

18.

19. public sta c void main(String[] args) {

20.
21. Honda obj=new Honda();

22. obj.bike();

23. }

24. }

Output:

Bike is running

Example 2: Abstract class containing the abstract and non-abstract method

1. abstract class Vehicle

2. {

3. abstract void bike();

4.

5. void car()

6. {

7. System.out.println("Car is running");

8. }

9.

10. }

11. class Honda extends Vehicle

12. {

13.

14. @Override

15. void bike() {

16. System.out.println("Bike is running");

17.

18. }

19.

20. }

21.

22. public class AbstractExample2 {

23.

24. public sta c void main(String[] args) {


25.

26. Honda obj=new Honda();

27. obj.bike();

28. obj.car();

29.

30. }

31.

32. }

Output:

Bike is running

Car is running

You might also like