answersLogoWhite

0

How do you write concrete method inside abstract class?

Updated: 8/20/2019
User Avatar

Wiki User

12y ago

Best Answer

There is no difference with method declaration and implementation between abstract and non-abstract classes.

You do the exact same thing when writing a concrete method in either an abstract or non-abstract class.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write concrete method inside abstract class?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you create a concrete method inside abstract class?

The same way you create a concrete method in a concrete class. When a class is abstract, it can contain abstract methods. That doesn't mean that all methods must be abstract. Hope this helps.


Can abstract class have constructors?

A constructor of a class in invoked when a object of that class is created. As an abstract class can't have an object, so we can't create a constructor of the abstract class. But we can create a constructor of a concrete subclass of that abstract class and we have to pass the object of that concrete subclass to the abstract class.


How do you invoke the abstract methods?

You cannot invoke abstract methods directly. An abstract method looks like below: public String getName() {} It has no code inside it and can do nothing. You cannot invoke it directly. If you want to call this method then - we must extend the class that contains this method inside our class and then provide an implementation for this method and then invoke it: Ex: public String getName() { return "Anand"; } Once you place this code inside your class, then you can invoke it anytime you want by calling the method "getName()"


Why don't use abstract keyword when we declare a method in interface?

The abstract keyword signifies that the particular method will have no features in the class where it is declared and it is upto the child class to provide the functionality. In case of an interface, the method is already abstract by default and has no code inside it. So there is no actual point in using the abstract keyword there.


When do you declare a method or class abstract in java?

when overriding of a class or a method is necessary, they can be declared as abstract


What is subclass of an abstract class called?

A Concrete class


What is concrete class in java?

A method which is not abstract i.e. if a methods definition is given in the same class its declared is called concrete. where as abstract method would have no definition till the deep down of the hierarchy of class structure but ll ve a declaration in all the subclasses and definition in one subclass after which it need not be declared in the further subclasses. By the way defining the abstract method in a subclass would end the carrying of the declaration till down, but defining it is not mandatory where declaring is mandatory.


What is concrete method?

class in which objects can be created is called as concrete class.


Write a Java Program to illustarte the use of abstract methods?

Abstract MethodsAn abstract method is a method that's been declared as abstract but not implemented. In other words, the method contains no code. You mark a method abstract when you want to force subclasses to provide the implementation. (remember the reason why you would want to make a class abstract from the previous paragraph)Ex: public abstract void showSample();Notice that the abstract method ends with a semicolon instead of curly braces. It is illegal to have even a single abstract method in a class that is not explicitly declared abstract! Look at the following illegal class:public class IllegalAbstractClass{public abstract void test();}The preceding class will produce the following error if you try to compile it:IllegalClass.java:1: class IllegalAbstractClass must be declaredabstract.It does not define void test() from class IllegalAbstractClass.public class IllegalAbstractClass {1 errorYou can, however, have an abstract class with no abstract methods. The following example will compile fine:public abstract class LegalAbstractClass{void test() {// you can write lots of code here}}In the preceding example, test() is not abstract. Three different clues tell you it's not an abstract method:• The method is not marked abstract.• The method declaration includes curly braces, as opposed to ending in a semicolon. In other words, the method has a method body.• The method contains actual implementation code.Any class that extends an abstract class must implement all abstract methods of the superclass, unless the subclass is also abstract. The rule is this:The first concrete subclass of an abstract class must implement all abstract methods of the superclass.Concrete just means nonabstract, so if you have an abstract class extending another abstract class, the abstract subclass doesn't need to provide implementations for the inherited abstract methods. Sooner or later, though, somebody's going to make a nonabstract subclass (in other words, a class that can be instantiated), and that subclass will have to implement all the abstract methods from up the inheritance tree.


Can abstract method be overriden?

An overridden method is one which has already been implemented in the parent class with the same signature but has again been coded in the current class for functionality requirements. An abstract method is one which has only been declared in a class and would have to be implemented by the class that extends this abstract class. The implementation for the method is not available in the class in which it is declared.


What is difference between interface and abstract class?

All the methods declared inside an Interface are abstract. Where as abstract class must have at least one abstract method and others may be concrete or abstract. In Interface we need not use the keyword abstract for the methods.


Can a class in java extend both abstract class and concrete class?

An Abstract class is similar to an interface. You cannot instantiate them, but you can extend them. Any class that extends the abstract class has to provide the implementation to the abstract methods. Hence these classes can be used as a skeleton to similar classes where some common functionality may be required. Such functionality can also be embedded into these classes. Unlike interfaces, abstract classes can have method code also. So they are very useful.