Can you use abstract and final both with a method? Why?

Asked by Last Modified  

34 Answers

Learn Java

Follow 3
Answer

Please enter your answer

Trainer

No because we have to provide an abstract method with implementation in the subclass (the child class of the parent class in which the abstract method was declared). And for providing this implementation the abstract method has to be overridden in the child class. Since final methods cannot be overridden...
read more
No because we have to provide an abstract method with implementation in the subclass (the child class of the parent class in which the abstract method was declared). And for providing this implementation the abstract method has to be overridden in the child class. Since final methods cannot be overridden so we can't declare a method both abstract and final as by doing so you won't be able to implement the method in the child class as it was declared both final and abstract in the parent class. read less
Comments

Experienced Java Professional

No, we can not declare abstract method as final. We have to proved implementation to abstract methods in subclasses. and method declared as final mean don't override (or redefine) this method. So the abstract and final combination is contradicting with each other.
Comments

Short Answer: No. Long Answer: Let's take a closer look at both keywords separately and try to understand their purpose before understanding the Why part of the question. An abstract method is a common behavior for which, each subclass will provide its own concrete implementation (or Override the abstract...
read more
Short Answer: No. Long Answer: Let's take a closer look at both keywords separately and try to understand their purpose before understanding the Why part of the question. An abstract method is a common behavior for which, each subclass will provide its own concrete implementation (or Override the abstract method). For example, consider an abstract class called Shape having an abstract method called getArea(). The abstract method doesn't know exactly how the area of the underlying shape will be calculated. But it just knows that each subclass of Shape needs to have a getArea() method. The concrete classes will decide how to compute the area. That is, the getArea() method inside Circle class will return area based on radius; while Rectangle class will return area based on length and breath. Similarly, other sub-classes will have their own concrete implementations. Now , coming to final keyword. If a method is declared as final, then it implies that this is the final implementation of this method and its behavior should not be modified at runtime by any subclass. If a method is declared as final, it cannot be Overriden by any subclass. For example, consider the abstract class House with methods getWindowCount() and getDoorCount(). Now, irrespective of the type of house (i.e. villa, appartment, bunglow, etc.), the concrete implementation of the above mentioned methods is not going to change. Hence, we can declare these methods as final and provide a concrete implementation in the House class itself. Since, you don't want someone to accidentally change the behavior of counting the number of windows and doors in the house based on its type. Conclusion: There are separate design considerations while choosing between the keywords abstract and final. When used on a method, they have completely opposite purposes. And since, there purpose are so opposite to each other (abstract methods mean provide implementation in sub-classes; while final methods mean DO NOT provide implementation in sub-classes), hence, it doesn't make sense to use them together on a single method. This is the reason, why Java compiler doesn't allow the usage of abstract and final keywords on a method. It throws a compile time error "illegal combination of modifiers: abstract and final". read less
Comments

10 years of Hadoop Spark Expertise

We should not write, because abstract meaning is partially implemented, so some one has to implement that, if we create that as final then we cant change that further.
Comments

More than 12 years of experience in IT Industry including Science/Computer teaching

No, Abstract method cannot be declared as final. This is because, abstract method has to be overridden to provide implementation. If it is declared as final, it cannot be overridden.
Comments

Java Trainer

No, Abstract is meant to be overridden in subclass so it wont have method body and final means it cannot be overridden in subclass and method body needs to be provided.
Comments

IT Professional Trainer with 13 years of experience in IT industry + Academics

Nope..... Because abstract methods are needed to be defined in the subclass..So you can't have abstract final method because then after you can not define it
Comments

Trainer

No, because we have to provide the implementation to methods in subclasses.
Comments

Experienced Software Professional

No. This is so because an abstract method is there for implementation. Putting a final is illegal. A Final method needs to have a body or implementation. Final restricts further overriding of the method in any derived class.
Comments

Computer Classes

No, we can not declare abstract method as final. We have to proved implementation to abstract methods in subclasses.
Comments

View 32 more Answers

Related Questions

Can I build iPhone apps using Python?
Yes, you can use PyMob app where apps can be written purely in Python, and the compiler tool flow converts them in native source codes for various platforms. But there are some cons on using PyMob, the...
Sunil
0 0
5
How do I learn Java? From book or internet or a coaching?
According to me....u should start from basic Java..that is core Java... . Find coaching , who teaches Java for beginners.....then later u can go for advance java.
Suresh
0 0
7
what is serialVersionUID , why it different for each bean? serialVersionUID = 42L;
This id is used to identify the type of the class. This is required when you serialize and de serialize the object. If you have given a value to this id, this will be common for all the objects created...
Srilatha N
Base obj=new Child(); What are the advantage and real life application of above code?
Have you ever observed while communicating with databases? You can find such type of example while writing code from communicating with DB. Connection connectionObject = DriverManager.getConnection(); or Statement...
Vijay

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Java: A Quick Overview
Not purely Object Oriented: It doesn't support multiple inheritence, it supports primitive data types and static members. Doesn’t support multiple inheritance: Reason is diamond problem i.e.,...

Method Overloading vs Method Overriding
1. Method Overloading: Method overloading means a same method with same name can have different implementations/body by changing one of the follwing thing: 1) Number of Parameters 2) Order of Parameters 3)...

Java exception handling in real time examples eavry application how we are interacting with exceptions
Exception Handling:====================For example, gmail account, we need emaid and passwrd if we entered correct account will be opened succusfuly if enterd wrong email or passwrd it shows error message...

JAVA Question 1 for beginners
String x="We are learning";String y="mistakes happen";int z=1000;System.out.println("Java is easy. "+x+" programming and "+y+" "+z +" times"); what is out put this code

Introduction to Course Content
Video about what we are going to learn throughout the Java Training Session .

Recommended Articles

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

Java is the most commonly used popular programming language for the creation of web applications and platform today. Integrated Cloud Applications and Platform Services Oracle says, “Java developers worldwide has over 9 million and runs approximately 3 billion mobile phones”.  Right from its first implication as java 1.0...

Read full article >

Java is the most famous programming language till date. 20 years is a big time for any programming language to survive and gain strength. Java has been proved to be one of the most reliable programming languages for networked computers. source:techcentral.com Java was developed to pertain over the Internet. Over...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you