Java abstract KeywordThe abstract keyword is used to achieve abstraction in Java. It is a non-access modifier which is used to create abstract class and method. The role of an abstract class is to contain abstract methods. However, it may also contain non-abstract methods. The method which is declared with abstract keyword and doesn't have any implementation is known as an abstract method. Syntax:-Note - We cannot declare abstract methods in non abstract class.Rules of abstract keywordDon'ts
Do's
Examples of abstract KeywordExample 1: Abstract class containing the abstract methodTest it NowOutput: Bike is running Example 2: Abstract class containing the abstract and non-abstract methodTest it NowOutput: Bike is running Car is running Example 3: Abstract class containing the constructorTest it NowOutput: Constructor is invoked Example 4: Abstract class containing overloaded abstract methodsTest it NowOutput: abstract method is invoked overloaded abstract method is invoked Example 5: Inner abstract classTest it NowOutput: inner abstract class is invoked Example 6: Nested abstract classTest it NowOutput: nested abstract class is invoked
Next TopicJava Boolean Keyword
|