Abstract Class In Java


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.
 

People who read this post also read :



73 comments:

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

Thanks for the post, I am techno savvy. I believe you hit the nail right on the head. I am highly impressed with your blog. It is very nicely explained. Your article adds best knowledge to our Java Online Training from India. or learn thru Java Online Training from India Students.

or learn thru JavaScript Online Training from India. Appreciating the persistence you put into your blog and detailed information you provide. Kindly keep blogging.

CIITN is the Best Php training institute in Noida and delhi Ncr. You will get Live Project Training on PHP by our PHP expert who have 5+ year industrial experience.Focus on practical and live project training. In our PHP training, we you will learn core PHP, advance PHP, HTML, CSS, JavaScript, jQuery, Bootstrap, Cake PHP and Wordpress.CIITN provides 100% job assistance in PHP training. CIITN is well known PHP coaching center because our 100% PHP students are placed now.


Ciitnoida provides Core and java training institute in noida. We have a team of experienced Java professionals who help our students learn Java with the help of Live Base Projects. The object-oriented, class-based build of Java has made it one of most popular programming languages and the demand of professionals with certification in Advance Java training is at an all-time high not just in India but foreign countries too.

By helping our students understand the fundamentals and Advance concepts of Java, we prepare them for a successful programming career. With over 13 years of sound experience, we have successfully trained hundreds of students in Noida and have been able to turn ourselves into an institute for best Java training in Noida.


java training institute in noida
php training in noida
linux training in noida
linux institute in noida
java course 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

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 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

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

The blog is well written,java is fast, secure and reliable platform. there are lots of application and websites works under java and it is platform independent.
JAVA Training in Coimbatore
JAVA Course in Coimbatore
JAVA Classes in Coimbatorer
Best JAVA Training in Coimbatore
JAVA Training Centers in Coimbatore

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

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

Thanks for sharing an information to us. If someone want to know about Ethical Hacking. I think this is the right place for you! ceh Training

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

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

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

Our many years of experience have made us leaders in language instruction and intercultural training. We have designed programs to create world-class executives with leadership capabilities in the global context. We are best english speaking course in noida because of following reasons:
Join English Speaking Course In Noida

Please continue this great work and I look forward to more of your awesome posts.

Java SE 8 Oracle training and certification course

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 .

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.

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More