Java Abstract classes are used to declare common characteristics of subclasses. An abstract class cannot be instantiated. It can only be used as a superclass for other classes that extend the abstract class. Abstract classes are declared with the abstract keyword. Abstract classes are used to provide a template or design for concrete subclasses down the inheritance tree.
Like any other class, an abstract class can contain fields that describe the characteristics and methods that describe the actions that a class can perform. An abstract class can include methods that contain no implementation. These are called abstract methods. The abstract method declaration must then end with a semicolon rather than a block. If a class has any abstract methods, whether declared or inherited, the entire class must be declared abstract. Abstract methods are used to provide a template for the classes that inherit the abstract methods.
Abstract classes cannot be instantiated; they must be subclassed, and actual implementations must be provided for the abstract methods. Any implementation specified can, of course, be overridden by additional subclasses. An object must have an implementation for all of its methods. You need to create a subclass that provides an implementation for the abstract method.
To declare that your class is an abstract class, use the keyword abstract before the class keyword in your class declaration:
abstract class Number {
. . .
}
If you attempt to instantiate an abstract class, the compiler displays an error similar to the following and refuses to compile your program:
AbstractTest.java:6: class AbstractTest is an abstract class.
It can't be instantiated.
new AbstractTest();
^
1 error
Points of abstract class :
1 Abstract class contains abstract methods.
2 Program can't instantiate an abstract class.
3 Abstract classes contain mixture of non-abstract and abstract methods.
4 If any class contains abstract methods then it must implements all the abstract methods of the abstract class.
Here is a simple example of a class with an abstract method, followed by a class which implements that method:
// A Simple demonstration of abstract.
abstract class A {
abstract void callme();
// concrete methods are still allowed in abstract classes
void callmetoo() {
System.out.println("This is a concrete method.");
}
}
class B extends A {
void callme() {
System.out.println("B's implementation of callme.");
}
}
class AbstractDemo {
public static void main(String args[]) {
B b = new B();
b.callme();
b.callmetoo();
}
}
Notice that no objects of class A are declared in the program. As mentioned, it is not possible to instantiate an abstract class. One other point: class A implements a concrete method called callmetoo( ). This is perfectly acceptable. Abstract classes can include as much implementation as they see fit.
Advantage of Abstract Classes
The advantage of using an abstract class is that you can group several related classes together as siblings. Grouping classes together is important in keeping a program organized and understandable.
An Abstract class is a way to organize inheritance, sometimes it makes no since to implement every method in a class (i.e. a predator class), it may implement some to pass to its children but some methods cannot be implemented without knowing what the class will do (i.e. eat() in a Tiger class). Therefore, abstract classes are templates for future specific classes.
Disadvantage of Abstract Classes
A disadvantage is that abstract classes cannot be instantiated, but most of the time it is logical not to create a object of an abstract class.
Like any other class, an abstract class can contain fields that describe the characteristics and methods that describe the actions that a class can perform. An abstract class can include methods that contain no implementation. These are called abstract methods. The abstract method declaration must then end with a semicolon rather than a block. If a class has any abstract methods, whether declared or inherited, the entire class must be declared abstract. Abstract methods are used to provide a template for the classes that inherit the abstract methods.
Abstract classes cannot be instantiated; they must be subclassed, and actual implementations must be provided for the abstract methods. Any implementation specified can, of course, be overridden by additional subclasses. An object must have an implementation for all of its methods. You need to create a subclass that provides an implementation for the abstract method.
To declare that your class is an abstract class, use the keyword abstract before the class keyword in your class declaration:
abstract class Number {
. . .
}
If you attempt to instantiate an abstract class, the compiler displays an error similar to the following and refuses to compile your program:
AbstractTest.java:6: class AbstractTest is an abstract class.
It can't be instantiated.
new AbstractTest();
^
1 error
Points of abstract class :
1 Abstract class contains abstract methods.
2 Program can't instantiate an abstract class.
3 Abstract classes contain mixture of non-abstract and abstract methods.
4 If any class contains abstract methods then it must implements all the abstract methods of the abstract class.
Here is a simple example of a class with an abstract method, followed by a class which implements that method:
// A Simple demonstration of abstract.
abstract class A {
abstract void callme();
// concrete methods are still allowed in abstract classes
void callmetoo() {
System.out.println("This is a concrete method.");
}
}
class B extends A {
void callme() {
System.out.println("B's implementation of callme.");
}
}
class AbstractDemo {
public static void main(String args[]) {
B b = new B();
b.callme();
b.callmetoo();
}
}
Notice that no objects of class A are declared in the program. As mentioned, it is not possible to instantiate an abstract class. One other point: class A implements a concrete method called callmetoo( ). This is perfectly acceptable. Abstract classes can include as much implementation as they see fit.
Advantage of Abstract Classes
The advantage of using an abstract class is that you can group several related classes together as siblings. Grouping classes together is important in keeping a program organized and understandable.
An Abstract class is a way to organize inheritance, sometimes it makes no since to implement every method in a class (i.e. a predator class), it may implement some to pass to its children but some methods cannot be implemented without knowing what the class will do (i.e. eat() in a Tiger class). Therefore, abstract classes are templates for future specific classes.
Disadvantage of Abstract Classes
A disadvantage is that abstract classes cannot be instantiated, but most of the time it is logical not to create a object of an abstract class.
70 comments:
Good presentation thanks for the helpful blog.
Regards,
Linux Online Training | Linux Training in Hyderabad | Linux Online Training in Hyderabad | Linux Online Training in India | Linux Online Training Institutes in Hyderabad | Best Institutes for Linux in Hyderabad | Linux Training Institutes in Hyderabad | Linux Training Institutes in India | Linux Online Training hyderabad | Linux Online Training India | Best Institutes for Linux | Linux Administration Training in Hyderabad
Nice Article .In short description good explanation. Thanks For sharing the informative news.
Regards,
Java Online Training | Java Online Training in India | Java Online Training India | Java Online Training in Hyderabad | Java Online Training Hyderabad | Java Training in Hyderabad | Java Training in India | Java Training Institutes in India | Java Training Institutes in Hyderabad | Java Course in Hyderabad | Java Training | Learn Java Online | Online Java Training | Best Java online Training Institutes in Hyderabad | Best Java Training Institutes in Hyderabad | Best Institutes for Java | Java Institutes in Hyderabad | Best Institutes for Java in Hyderabad | Learn Java | Java Training Institutes in Hyderabad | Java Certification | Java Certification Training | Java Certification Training in Hyderabad | Java Certification Training in India
Thanks for sharing this good blog.This is very important and imformative
blog for Java . very interesting and usefulblog
Java Online Training Hyderabad
Great Blog , Gives an excellence Knowledge about Abstract Class concept in Java and it's Very informative.
Thanks for sharing this good blog. It's very interesting and useful for students Java Online Course
The Blog Content is very informative and helpful. Please share more content. Thanks.
JAVA Training
JAVA Institute
JAVA Course
Thanks, Learned a lot of new things from your post! Good creation and HATS OFF to the creativity of your mind.
Very interesting and useful blog!
Java Training in Gurgaon
Thanks for posting the useful information to my vision. This is excellent information,.
iphone app training course in hyd
Learned a lot of new things from your post!Good creation ,It's amazing blog
Core Java Online Training
Java Online Course
Java Online Training Bangalore
Nice post. Thanks for this awesome blog. Keep sharing
Java Training in Noida
Java based-article, such a great post for java developers and learners.
BEST JAVA TRAINING IN NOIDA
BEST DIGITAL MARKETING TRAINING IN NOIDA
BEST TRAINING IN NOIDA
CIITN provides Best java training in noida based on current industry standards that helps attendees to secure placements in their dream jobs at MNCs.The curriculum of our Java training institute in Noida is designed in a way to make sure that our students are not just able to understand the important concepts of the programming language but are also able to apply the knowledge in a practical way.
if you are looking for the best oracle sql certification center in Noida, CIIT is worth to consider. CIIT is a oracle training institute offering best sql course, oracle training, sql certification and oracle dba training at affordable price. Best Oracle training in Noida.
Java Training in Noida
best java training in noida
Really awesome blog. Your blog gives very useful information. Thanks for sharing. Top Java training in Hyderabad.
I would say while reading your article, I felt very proud,because the information you written very useful, please keep posting this type of articles. If you guys looking for a training institutes for java or advanced java, please click below link.
Advanced Java Training In Bangalore
Thanks for sharing the useful information, If you are looking for Best Java Training Institute in Chennai, Please visit the below linksCore Java Training in Chennai | J2EE Training in Chennai | Hibernate Training in Chennai | Spring Training in Chennai | Struts Training in Chennai
Best digital marketing summer training
Best PHP summer training
Best 6 weeks embedded system summer training
I was more than happy to uncover this great site.
Web Designing Training In Bangalore
Web Design Courses In Bangalore
Java Training In Bangalore
iOS Training In Bangalore
I would like to say that this blog really convinced me to update my knowledge about the technology you talk about. Thanks, very good post.
JAVA Course in Chennai
Best JAVA Training in Chennai
Techonolgy is updated day to day
Thanks for sharing the info
Best Salesforce Training
Learn Online DevOps Training
Hi Your Blog is very nice!!
Get All Top Interview Questions and answers PHP, Magento, laravel,Java, Dot Net, Database, Sql, Mysql, Oracle, Angularjs, Vue Js, Express js, React Js,
Hadoop, Apache spark, Apache Scala, Tensorflow.
Mysql Interview Questions for Experienced
php interview questions for freshers
php interview questions for experienced
python interview questions for freshers
tally interview questions and answers
Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
Java Training in Chennai | Java Training Institute in Chennai
Hi, Your blog is very helpfull thanks for the information..........
successit
SAP Training Institute in Hyderabad and Banaglore, SuccessIT provides SAP Online Training, Class room training, SAP MM online training, SAP SRM training, SAP WM training, SAP S/4, SAP EWM, BI, BO, FICO, PM, PS,more at LowFee.As the Leading SAP-EWM Training Institute , We have more than 15+ years of training experience in SAP and as well as Real –time working experience in all SAP modules Success IT is The Best SAP EWM Online Training Institute in Hyderabad, Bangalore, we provide Online and Class Room Training for SAP EWM Module at Low Fee. SAP EWM Coaching etc..
Hello, Thanks for sharing such a valuable information
Real Trainings offers all IT-Training and Non-IT Training Institutes information in Hyderabad, Bangalore, Chennai . Here students can Compare all Courses with all detailed information.In Banks Coaching provides Bank Coaching Training Institutes in Hyderabad, IBPS PO , CLERK Training , SBI PO ,CLERK Training, RRB OFFICER ,ASSISTANT Training ,Bank Coaching training institutes, Bank Coaching online training classes in Hyderabad etc.
Thank you for post valuable information
Mobile app development company in chennai
Web development company in chennai
Web design company in chennai
Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
iphone training classes in bangalore
ios course fee in bangalore
Thanks For useful information.
Java Placement Job Oriented Training
Abstraction is an useful feature of OOPs. java training in chennai
this is an awesome post.really very informative and creative contents. these concepts are good way to enhance knowledge.J2EE course in chennai
Excellent Blog
Thank you for sharing this post. I wonder to visit your Blog and to gain informative knowledge.
iphone training classes in bangalore
best ios training institute in bangalore
Nice blog..! I really loved reading through this article. Thanks for sharing such a amazing post with us and keep blogging...
Hadoop online training in Hyderabad
Hadoop training in Hyderabad
Bigdata Hadoop training in Hyderabad
Great Post. Keep sharing such kind of worthy information
Java Courses in Chennai
core Java training in chennai
UiPath Training in Bangalore by myTectra is one the best UiPath Training. myTectra is the market leader in providing Robotic Process Automation on UiPath
ui path training in bangalore
Hi Nice Post,For More Updates
Files in Gachibowli
I really enjoy the blog.Much thanks again. Really Great core Java online training Bangalore
Nice blog it was so informative and helpful. Thanks for sharing..keep update Selenium Testing Course
software testing course in velachery chennai
Hey Nice Blog!! Thanks For Sharing!!!Wonderful blog & good post.Its really helpful for me, waiting for a more new post. Keep Blogging!
advanced java training in coimbatore
php training centre in coimbatore
Such a nice post. KDSS Technologies provides the best software development services to its clients along with other IT services.That is what makes it one of the best software development company in Delhi NCR | software development company in Delhi
Thank you for allowing me to read it, welcome to the next in a recent article. And thanks for sharing the nice article, keep posting or updating news article.
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
You’ve written a really great article here. Your writing style makes this material easy to understand.. I agree with some of the many points you have made. Thank you for this is real thought-provoking content
python Training in Pune
python Training in Chennai
python Training in Bangalore
Hi Nice Post,For More Updates
Files in Gachibowli
I gathered lots of information from your blog and it helped me a lot. Keep posting more.
Blue Prism Training in Chennai
Blue Prism Training Institute in Chennai
UiPath Training in Chennai
Robotics Process Automation Training in Chennai
RPA Training in Chennai
Data Science Course in Chennai
Blue Prism Training in OMR
Blue Prism Training in Adyar
Its a wonderful post and very helpful, thanks for all this information.
Java Training in Delhi
MEAN Stack Training in Chennai MEAN Stack Training in Chennai with real time projects. We are Best MEAN Stack Training Institute in Chennai. Our Mean Stack courses are taught by Industrial Experts which would help you to learn MEAN Stack development from the scratch.
The information which you have provided is very good. It is very useful who is looking for Java Learning
Thank your valuable content.we are very thankful to you.one of the recommended blog.which is very useful to new learners and professionals.content is very useful for hadoop learners
Best ASP.NET MVC Online Training Institute
Best Spring Online Training Institute
Best Devops Online Training Institute
Best Datascience Online Training Institute
Best Oracle Online Training Institute
Best AWS Online Training Institute
Best AngularJS Online Training Institute
The blog you have shared really worth for me.Thanks for Sharing...
erp providers in india
RPA Providers Chennai
erp software development companies in india
erp in chennai
Thanks first of all for the useful info.the idea in this article is quite different and innovative please update more.
Big data training in chennai
Software testing training in chennai
Selenium Training in Chennai
Python Training in Chennai
JAVA Training in Annanagar
java training in chennai anna nagar
Haveing seen your blog i am very happy thanks for shareing such valuable information keep continue this blogging job, here you can learn C language C is the precursor and inspirer for almost all the most popular high-level languages available today.
C Language Training In Greater Noida
C Language Training Institute In Greater Noida
C Language Course In Greater Noida
C Language Tranning In Greater Noida
Thanks for posting this blog. I really love while reading it.
Python Corporate training in Nigeria
Please continue this great work and I look forward to more of your awesome posts.
Java SE 8 Oracle training and certification course
Excellent blog, I wish to share your post with my folks circle. It’s really helped me a lot, so keep sharing post like this.
advanced java training institutes in bangalore
advanced java training in bangalore
best advanced java training institutes in bangalore
advanced java training course content
advanced java training interview questions
advanced java training & placement in bangalore
advanced java training center in bangalore
Searching for Bank Coaching in Noida? Pinnacle Institute is Brilliant Bank Coaching in Noida .Pinnacle directs you in accomplishing your valuable dream by honing you aptitudes. We have well-qualified and skilled educators who give proper direction to the inside and out proficient development of the students.
I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.i want to share about java advanced tutorials and advanced java training videos .
Thanks for sharing.
Machine Learning training in Pallikranai Chennai
Pytorch training in Pallikaranai chennai
Data science training in Pallikaranai
Python Training in Pallikaranai chennai
Deep learning with Pytorch training in Pallikaranai chennai
Bigdata training in Pallikaranai chennai
Mongodb Nosql training in Pallikaranai chennai
Spark with ML training in Pallikaranai chennai
Data science Python training in Pallikaranai
Bigdata Spark training in Pallikaranai chennai
Sql for data science training in Pallikaranai chennai
Sql for data analytics training in Pallikaranai chennai
Sql with ML training in Pallikaranai chennai
Good post and I like it very much.
oracle training in chennai
oracle training institute in chennai
oracle training in bangalore
oracle training in hyderabad
oracle training
hadoop training in chennai
hadoop training in bangalore
Nice blog..! I really loved reading through this article. Thanks for sharing such a amazing post with us and keep blogging...
python Training in chennai
python Course in chennai
Nice Article ! I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
Nice Article ! I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
RR Technosoft offering Best DevOps Training in Hyderabad.Get trained by 15+ years of real-time IT experience, 4+ years of DevOps & AWS experience. RR Technosoft is one of the trusted institutes for DevOps classroom & Online training.For more information contact (+91)-7680001943.
Thank you for your post. This is useful information.
Java Online Training Hyderabad
Visit us: Java Online Training Hyderabad
Thank you for sharing this post its very knowledgeable i hope that you will continue to post these kinds of contents in future apart from that if anyone looking for Advance Excel institute in delhi so Contact Here-+91-9311002620 Or Visit Website- https://www.htsindia.com/Courses/business-analytics/adv-excel-training-course
Your info is really amazing with impressive content..Excellent blog.
Visit us: Java Online Training Hyderabad
Visit us: Core Java Online Course
Visit us: java course
That is nice article from you , this is informative stuff . Hope more articles from you . I also want to share some information about Pet Dermatology in Vizag
Nice blog..! I really loved reading through this article... Thanks for sharing such an amazing post with us and keep blogging...Signova Group
Thanks for the blog article.Thanks Again. Keep writing.
java training
online training in java
"Hi, I have just started to Learn Java Certification Online. and this blog is really informative for me. Thank you for this blog!"
This is an awesome post. Really very informative and creative contents. Visit my website to get best Information About Best UPSC Coaching Institute in Maharashtra.
Best UPSC Coaching Institute in Maharashtra
Top UPSC Coaching Institute in Maharashtra
Thanks for this post. It proves very informative for me. Great post to read. Visit my website to get best Information About Best MPSC Coaching Institute in Vasai.
Best MPSC Coaching Institute in Vasai
Top MPSC Coaching Institute in Vasai
Thank you for the post. Digital Marketing course in Gurgaon is best institute to learn digital marketing.
CGS Hospital Gurgaon is a premier healthcare facility dedicated to your well-being. With a team of experienced doctors, cutting-edge technology, CGS Hospital Gurgaon a commitment to compassionate care, we offer a wide range of medical services.
Nice Article Keep Posting.
Web desgining course in hyderabad
Nice post. Thanks for posting.
Java course in Pune
Post a Comment