title
8.18 Abstract Class in Java Example

description
An abstract class is an incomplete class. An abstract class is defined with the keyword abstract . We cannot create an object of the abstract class because it is not complete. These classes cannot be instantiated and are either partially implemented or not at all implemented. This class contains one or more abstract methods which are simply method declarations without a body. This class is used when common features are shared by all object. Java and Spring Framework For beginners with Spring Boot : - http://bit.ly/3LDMj8D Java Tutorial for Beginners (2023) :- http://bit.ly/3yARVbN Editing Monitors : https://amzn.to/2RfKWgL https://amzn.to/2Q665JW https://amzn.to/2OUP21a. Editing Laptop : ASUS ROG Strix - (new version) https://amzn.to/2RhumwO Camera : https://amzn.to/2OR56AV lens : https://amzn.to/2JihtQo Mics https://amzn.to/2RlIe9F https://amzn.to/2yDkx5F Check out our website: http://www.telusko.com Follow Telusko on Twitter: https://twitter.com/navinreddy20 Follow on Facebook: Telusko : https://www.facebook.com/teluskolearnings Navin Reddy : https://www.facebook.com/navintelusko Follow Navin Reddy on Instagram: https://www.instagram.com/navinreddy20 Subscribe to our other channel: Navin Reddy : https://www.youtube.com/channel/UCxmkk8bMSOF-UBF43z-pdGQ?sub_confirmation=1 Telusko Hindi : https://www.youtube.com/channel/UCitzw4ROeTVGRRLnCPws-cw?sub_confirmation=1 Subscribe to the channel and learn Programming in easy way. Java Tutorial for Beginners : https://goo.gl/p10QfB Scala Tutorials for Java Developers : https://goo.gl/8H1aE5 C Tutorial Playlist : https://goo.gl/8v92pu Android Tutorial for Beginners Playlist : https://goo.gl/MzlIUJ XML Tutorial : https://goo.gl/Eo79do Design Patterns in Java : https://goo.gl/Kd2MWE Socket Programming in Java : https://goo.gl/jlMEbg Spring MVC Tutorial : https://goo.gl/9ubbG2 OpenShift Tutorial for Beginners : https://goo.gl/s58BQH Spring Framework with Maven : https://goo.gl/MaEluO Sql Tutorial for Beginners : https://goo.gl/x3PrTg String Handling in Java : https://goo.gl/zUdPwa Array in Java : https://goo.gl/uXTaUy Java Servlet : https://goo.gl/R5nHp8 Exception Handling in Java : https://goo.gl/N4NbAW

detail
{'title': '8.18 Abstract Class in Java Example', 'heatmap': [{'end': 883.157, 'start': 852.677, 'weight': 0.755}], 'summary': 'Explores the concept of abstract class and methods through examples of phone features, inheritance, and abstraction, promoting code reusability and flexibility in object-oriented programming in java.', 'chapters': [{'end': 275.076, 'segs': [{'end': 211.724, 'src': 'embed', 'start': 185.911, 'weight': 1, 'content': [{'end': 192.956, 'text': 'how to define how to provide the implementation for move, how to how a phone will dance or how a phone will cook.', 'start': 185.911, 'duration': 7.045}, {'end': 195.117, 'text': 'but he wants those features.', 'start': 192.956, 'duration': 2.161}, {'end': 197.819, 'text': "so he cannot define it because he don't know how to do it.", 'start': 195.117, 'duration': 2.702}, {'end': 199.501, 'text': 'so he is declaring it.', 'start': 197.819, 'duration': 1.682}, {'end': 204.004, 'text': 'and whenever you declare the methods, this methods become abstract.', 'start': 199.501, 'duration': 4.503}, {'end': 211.724, 'text': "since you don't know the implementation or you don't want to provide the implementation, you make the methods abstract.", 'start': 205.382, 'duration': 6.342}], 'summary': 'Declaring methods as abstract when implementation is unknown or unwanted.', 'duration': 25.813, 'max_score': 185.911, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RcIsb9iFKH8/pics/RcIsb9iFKH8185911.jpg'}, {'end': 275.076, 'src': 'embed', 'start': 224.209, 'weight': 0, 'content': [{'end': 229.291, 'text': 'so this is declaration and this is definition, as we have seen in the theory.', 'start': 224.209, 'duration': 5.082}, {'end': 230.591, 'text': 'now the problem is whenever.', 'start': 229.291, 'duration': 1.3}, {'end': 234.453, 'text': 'so this this method here, this methods are called as abstract method.', 'start': 230.591, 'duration': 3.862}, {'end': 238.599, 'text': 'so these are abstract methods.', 'start': 235.677, 'duration': 2.922}, {'end': 241.241, 'text': 'now, since you have abstract methods here.', 'start': 238.599, 'duration': 2.642}, {'end': 250.127, 'text': "so the class which has abstract method, the class should be abstract class and you can see there's no error now here,", 'start': 241.241, 'duration': 8.886}, {'end': 254.931, 'text': 'because you can have abstract methods inside abstract class.', 'start': 250.127, 'duration': 4.804}, {'end': 268.074, 'text': 'but the problem is you cannot instantiate, cannot instantiate the object or cannot instantiate the abstract class,', 'start': 254.931, 'duration': 13.143}, {'end': 270.875, 'text': 'which simply means you cannot create object of abstract class.', 'start': 268.074, 'duration': 2.801}, {'end': 272.135, 'text': "it's that simple?", 'start': 270.875, 'duration': 1.26}, {'end': 275.076, 'text': 'okay, so this will not work.', 'start': 272.135, 'duration': 2.941}], 'summary': 'Abstract classes cannot be instantiated and can have abstract methods.', 'duration': 50.867, 'max_score': 224.209, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RcIsb9iFKH8/pics/RcIsb9iFKH8224209.jpg'}], 'start': 0.779, 'title': 'Abstract class', 'summary': 'Discusses the concept of an abstract class and methods using the example of a phone, where mahesh wants to add new features like calling, moving, dancing, and cooking, leading to the declaration of abstract methods and the creation of an abstract class.', 'chapters': [{'end': 275.076, 'start': 0.779, 'title': 'Abstract class: the concept and implementation', 'summary': 'Discusses the concept of an abstract class and methods using the example of a phone, where mahesh wants to add new features like calling, moving, dancing, and cooking, but is unsure of their implementation, leading to the declaration of abstract methods and the creation of an abstract class.', 'duration': 274.297, 'highlights': ['The concept of an abstract class and methods is explained using the example of a phone, where Mahesh wants to add new features like calling, moving, dancing, and cooking, but is unsure of their implementation. The chapter illustrates the concept of an abstract class and methods using the example of a phone, where Mahesh aims to add new features like calling, moving, dancing, and cooking but lacks clarity on their implementation.', 'The process of declaring abstract methods and creating an abstract class is demonstrated, with the explanation that abstract methods are those which are declared but not defined, and the presence of abstract methods necessitates a class to be an abstract class. The chapter illustrates the process of declaring abstract methods and creating an abstract class, explaining that abstract methods are declared but not defined, leading to the requirement for a class to be an abstract class.', 'The limitations of an abstract class are highlighted, stating that an abstract class cannot be instantiated, meaning an object of an abstract class cannot be created. The chapter emphasizes the limitations of an abstract class, stating that it cannot be instantiated, thus preventing the creation of an object of an abstract class.']}], 'duration': 274.297, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RcIsb9iFKH8/pics/RcIsb9iFKH8779.jpg', 'highlights': ['The process of declaring abstract methods and creating an abstract class is demonstrated, with the explanation that abstract methods are those which are declared but not defined, and the presence of abstract methods necessitates a class to be an abstract class.', 'The concept of an abstract class and methods is explained using the example of a phone, where Mahesh wants to add new features like calling, moving, dancing, and cooking, but is unsure of their implementation.', 'The limitations of an abstract class are highlighted, stating that an abstract class cannot be instantiated, meaning an object of an abstract class cannot be created.']}, {'end': 622.481, 'segs': [{'end': 344.944, 'src': 'embed', 'start': 319.761, 'weight': 0, 'content': [{'end': 324.586, 'text': 'so Ramesh wanted some other features, but he was not getting what features we need.', 'start': 319.761, 'duration': 4.825}, {'end': 332.054, 'text': 'so he went to his library and in that library he found there is already a article written on a phone by Mahesh,', 'start': 324.586, 'duration': 7.468}, {'end': 334.897, 'text': 'and Mahesh says every phone should have this four features.', 'start': 332.054, 'duration': 2.843}, {'end': 338.38, 'text': 'one of them is defined by me.', 'start': 335.778, 'duration': 2.602}, {'end': 340.281, 'text': "it's up to you to define this.", 'start': 338.38, 'duration': 1.901}, {'end': 341.362, 'text': 'so what Ramesh did?', 'start': 340.281, 'duration': 1.081}, {'end': 344.944, 'text': 'Ramesh says okay, I will extend Mahesh phone.', 'start': 341.362, 'duration': 3.582}], 'summary': 'Ramesh found 4 essential phone features in a library article by mahesh, and decided to extend his own phone accordingly.', 'duration': 25.183, 'max_score': 319.761, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RcIsb9iFKH8/pics/RcIsb9iFKH8319761.jpg'}, {'end': 445.218, 'src': 'embed', 'start': 420.63, 'weight': 3, 'content': [{'end': 429.533, 'text': 'since Ramesh failed to define these two classes, these two methods, we cannot create object of Ramesh phone because this is again abstract.', 'start': 420.63, 'duration': 8.903}, {'end': 439.236, 'text': "So example if I, even if I try now, if I, let's keep it Mahesh, because the concept is of Mahesh right, if I, if I write it Ramesh,", 'start': 430.073, 'duration': 9.163}, {'end': 445.218, 'text': 'here still we are getting error because Ramesh is an abstract class, so cannot instantiate the type Ramesh phone.', 'start': 439.236, 'duration': 5.982}], 'summary': 'Ramesh failed to define classes and methods, preventing object creation of ramesh phone.', 'duration': 24.588, 'max_score': 420.63, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RcIsb9iFKH8/pics/RcIsb9iFKH8420630.jpg'}, {'end': 536.625, 'src': 'embed', 'start': 508.846, 'weight': 2, 'content': [{'end': 519.332, 'text': "and he also defined one more method, which is public void, which is cook, and we'll say this is out cooking.", 'start': 508.846, 'duration': 10.486}, {'end': 521.554, 'text': 'and now you can see, there is no error.', 'start': 519.332, 'duration': 2.222}, {'end': 523.216, 'text': 'so what Suresh did?', 'start': 521.554, 'duration': 1.662}, {'end': 526.318, 'text': 'he tried to implement all the methods.', 'start': 523.216, 'duration': 3.102}, {'end': 530.121, 'text': 'now the advantage is you cannot create object of Ramesh phone because it is abstract.', 'start': 526.318, 'duration': 3.803}, {'end': 536.625, 'text': 'right, but you can create object of Suresh phone because Suresh phone here is called as.', 'start': 530.121, 'duration': 6.504}], 'summary': "Suresh implemented methods, making his phone accessible while ramesh's remains abstract.", 'duration': 27.779, 'max_score': 508.846, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RcIsb9iFKH8/pics/RcIsb9iFKH8508846.jpg'}], 'start': 275.076, 'title': 'Phone class concepts', 'summary': "Covers mahesh's attempt to define phone features, ramesh's extension of mahesh's phone based on the mentioned features, inheritance, and abstraction using the example of mahesh, ramesh, and suresh, implementation of abstract classes, and concrete classes using the example of phone classes.", 'chapters': [{'end': 344.944, 'start': 275.076, 'title': 'Creating future phone features', 'summary': "Discusses mahesh's attempt to define phone features in an article and ramesh's extension of mahesh's phone based on the mentioned features.", 'duration': 69.868, 'highlights': ["Ramesh extended Mahesh's phone based on the four features mentioned in Mahesh's article.", 'Mahesh wrote an article proposing that future phones should have four specific features.']}, {'end': 473.318, 'start': 344.944, 'title': 'Inheritance and abstraction in phone classes', 'summary': "Explains the concept of inheritance and abstraction using the example of mahesh, ramesh, and suresh, where mahesh's features are extended, ramesh failed to define abstract methods, resulting in an abstract class, and suresh attempts to build a phone following the same concept.", 'duration': 128.374, 'highlights': ['Ramesh phone has four methods: call method, move (defined in Ramesh), and two extra abstract methods.', "Ramesh's failure to define the two abstract methods resulted in Ramesh phone being an abstract class, preventing the instantiation of objects of Ramesh phone.", 'Suresh attempts to build a phone following the concept of Mahesh and Ramesh, as described in an article, and aims to define the necessary methods for the phone.']}, {'end': 622.481, 'start': 473.798, 'title': 'Abstract class example with phone', 'summary': 'Discusses the implementation of abstract classes and concrete classes using the example of phone classes, demonstrating how abstract classes can be used to define methods without implementation, and concrete classes can extend and implement those methods, allowing for the creation of objects and calling of methods.', 'duration': 148.683, 'highlights': ['Suresh extended Ramesh phone and defined methods dance and cook as public void, enabling the creation of objects of Suresh phone, a concrete class, which can implement the abstract methods of Ramesh phone.', 'Abstract classes like Mahesh phone and Ramesh phone cannot be instantiated, but their methods can be called through concrete classes like Suresh phone, showcasing the advantage of using abstract classes.', 'The use of abstract classes is illustrated through the analogy of a project manager providing the structure and required methods for a project, leaving the implementation to be defined by the extending class, highlighting the practical application of abstract classes in software development.']}], 'duration': 347.405, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RcIsb9iFKH8/pics/RcIsb9iFKH8275076.jpg', 'highlights': ["Ramesh extended Mahesh's phone based on the four features mentioned in Mahesh's article.", 'Mahesh wrote an article proposing that future phones should have four specific features.', 'Suresh extended Ramesh phone and defined methods dance and cook as public void, enabling the creation of objects of Suresh phone, a concrete class, which can implement the abstract methods of Ramesh phone.', 'Abstract classes like Mahesh phone and Ramesh phone cannot be instantiated, but their methods can be called through concrete classes like Suresh phone, showcasing the advantage of using abstract classes.']}, {'end': 925.232, 'segs': [{'end': 650.923, 'src': 'embed', 'start': 622.481, 'weight': 0, 'content': [{'end': 631.933, 'text': "so let's say we have the first class as iphone and in this iphone class we have a method which is public void show config, okay,", 'start': 622.481, 'duration': 9.452}, {'end': 644.74, 'text': "which prints the configuration of iphone, which is iphone has 2gb ram i'm talking about iphone 6s and it has ios 9.3 version right.", 'start': 631.933, 'duration': 12.807}, {'end': 650.923, 'text': 'and then we have one more class which is class samsung s4, because i have these two phones with me.', 'start': 644.74, 'duration': 6.183}], 'summary': 'Comparison of iphone 6s and samsung s4 classes', 'duration': 28.442, 'max_score': 622.481, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RcIsb9iFKH8/pics/RcIsb9iFKH8622481.jpg'}, {'end': 834.96, 'src': 'embed', 'start': 805.765, 'weight': 1, 'content': [{'end': 809.307, 'text': 'but the problem is, if you create only one method, what should be the parameter?', 'start': 805.765, 'duration': 3.542}, {'end': 810.608, 'text': 'it should be iPhone or S4?', 'start': 809.307, 'duration': 1.301}, {'end': 813.05, 'text': "that's the confusion right.", 'start': 810.608, 'duration': 2.442}, {'end': 817.332, 'text': 'so to solve this problem, what we can do is we can use something called as abstraction here,', 'start': 813.05, 'duration': 4.282}, {'end': 834.96, 'text': "which means create abstract class and we'll name this class as phone, in which you'll be having one method which is public abstract void show config.", 'start': 817.332, 'duration': 17.628}], 'summary': "To solve the problem of choosing between iphone and s4, an abstract class 'phone' with a method 'show config' can be used.", 'duration': 29.195, 'max_score': 805.765, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RcIsb9iFKH8/pics/RcIsb9iFKH8805765.jpg'}, {'end': 890.144, 'src': 'heatmap', 'start': 852.677, 'weight': 2, 'content': [{'end': 858.543, 'text': 'And here, instead of creating the instead of taking the parameter as iPhone, just take the parameter as phone.', 'start': 852.677, 'duration': 5.866}, {'end': 860.365, 'text': "So we don't require these two methods.", 'start': 858.923, 'duration': 1.442}, {'end': 871.875, 'text': 'So even if you pass object of iPhone, this phone will accept it because you can pass the object of subclass and the reference of superclass.', 'start': 862.093, 'duration': 9.782}, {'end': 875.116, 'text': "So that's the awesomeness of abstraction.", 'start': 872.095, 'duration': 3.021}, {'end': 877.676, 'text': 'We can pass obj, we can pass obj1.', 'start': 875.616, 'duration': 2.06}, {'end': 880.297, 'text': 'Depending upon what you pass, it will display those things.', 'start': 877.696, 'duration': 2.601}, {'end': 883.157, 'text': 'Since we are passing obj1, it says lollipop.', 'start': 880.957, 'duration': 2.2}, {'end': 887.058, 'text': 'If you pass just obj, it will show iPhone.', 'start': 883.217, 'duration': 3.841}, {'end': 890.144, 'text': 'sounds good.', 'start': 889.164, 'duration': 0.98}], 'summary': 'Using abstraction, a phone can accept objects of subclasses and references of superclasses, displaying the corresponding information.', 'duration': 28.051, 'max_score': 852.677, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RcIsb9iFKH8/pics/RcIsb9iFKH8852677.jpg'}], 'start': 622.481, 'title': 'Object-oriented programming and abstraction in java', 'summary': 'Discusses an object-oriented programming example for iphone and samsung s4, along with abstraction in java through the creation of abstract and concrete classes, promoting code reusability and flexibility.', 'chapters': [{'end': 726.464, 'start': 622.481, 'title': 'Object-oriented programming example', 'summary': 'Discusses a code example illustrating object-oriented programming concepts with a focus on creating classes for iphone and samsung s4, including their methods and configurations, and the usage of objects in the context of the code.', 'duration': 103.983, 'highlights': ['The chapter introduces classes for iPhone and Samsung S4, each including a method to display the configuration of the respective phone models, with the iPhone 6s having a 2GB RAM and iOS 9.3 version, and the Samsung S4 having 2GB RAM and Loripop OS.', 'The code example demonstrates the creation of an object of the iPhone class and the passing of this object as a parameter to a static method, resulting in an error that is discussed in the context of the code.']}, {'end': 925.232, 'start': 726.464, 'title': 'Abstraction in java', 'summary': "Discusses the concept of abstraction in java, demonstrating the creation of an abstract class 'phone' with an abstract method 'show config', which is extended by concrete classes iphone and samsung to achieve polymorphism, promoting code reusability and flexibility.", 'duration': 198.768, 'highlights': ["The chapter discusses the concept of abstraction in Java, demonstrating the creation of an abstract class 'phone' with an abstract method 'show config', which is extended by concrete classes iPhone and Samsung to achieve polymorphism, promoting code reusability and flexibility. The concept of abstraction is exemplified through the creation of an abstract class 'phone' with the abstract method 'show config', illustrating how this class is extended by concrete classes iPhone and Samsung to achieve polymorphism, promoting code reusability and flexibility.", 'The chapter explains the advantage of using abstraction by enabling the passing of objects of subclasses as parameters to a method defined with the superclass reference, showcasing the flexibility and reusability of code. The advantage of using abstraction is explained through the flexibility and reusability of code, as demonstrated by the ability to pass objects of subclasses as parameters to a method defined with the superclass reference.', 'The video also highlights that an abstract class can have both abstract and normal methods, providing flexibility in method definitions within the abstract class. The video emphasizes that an abstract class can contain both abstract and normal methods, showcasing the flexibility in method definitions within the abstract class.']}], 'duration': 302.751, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RcIsb9iFKH8/pics/RcIsb9iFKH8622481.jpg', 'highlights': ['The chapter introduces classes for iPhone and Samsung S4, each including a method to display the configuration of the respective phone models, with specific RAM and OS details.', "The chapter discusses the concept of abstraction in Java, demonstrating the creation of an abstract class 'phone' with an abstract method 'show config', which is extended by concrete classes iPhone and Samsung to achieve polymorphism, promoting code reusability and flexibility.", 'The advantage of using abstraction is explained through the flexibility and reusability of code, as demonstrated by the ability to pass objects of subclasses as parameters to a method defined with the superclass reference.']}], 'highlights': ['The advantage of using abstraction is explained through the flexibility and reusability of code, as demonstrated by the ability to pass objects of subclasses as parameters to a method defined with the superclass reference.', "The chapter discusses the concept of abstraction in Java, demonstrating the creation of an abstract class 'phone' with an abstract method 'show config', which is extended by concrete classes iPhone and Samsung to achieve polymorphism, promoting code reusability and flexibility.", 'Abstract classes like Mahesh phone and Ramesh phone cannot be instantiated, but their methods can be called through concrete classes like Suresh phone, showcasing the advantage of using abstract classes.', 'Suresh extended Ramesh phone and defined methods dance and cook as public void, enabling the creation of objects of Suresh phone, a concrete class, which can implement the abstract methods of Ramesh phone.', "Ramesh extended Mahesh's phone based on the four features mentioned in Mahesh's article.", 'The process of declaring abstract methods and creating an abstract class is demonstrated, with the explanation that abstract methods are those which are declared but not defined, and the presence of abstract methods necessitates a class to be an abstract class.', 'The concept of an abstract class and methods is explained using the example of a phone, where Mahesh wants to add new features like calling, moving, dancing, and cooking, but is unsure of their implementation.', 'The limitations of an abstract class are highlighted, stating that an abstract class cannot be instantiated, meaning an object of an abstract class cannot be created.']}