Quantcast
answersLogoWhite
notificationBell

Top Answer
User Avatar
Wiki User
Answered 2012-03-04 02:41:47

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.

001
๐Ÿ™๐Ÿฟ
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0
User Avatar

Your Answer

Still Have Questions?

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.


What is difference between Abstract Class and Interface?

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.


What is the advantage of abstract classes over interfaces?

The main advantage of an abstract class it the fact that, you can actually write methods that are not abstract. i.e., you can write methods with concrete code inside them. So when an abstract class is extended, all the abstract methods will be implemented by the child class but the child class will also inherit the code of this concrete method you wrote in the abstract class. This is the only thing an interface cannot do and is the advantage of an abstract class over an interface.


Can you write constructor inside an abstract class?

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.


What is abstract class in Java?

a abstract class is class which has a abstract method which means a method does not its own body.


Why cannot abstract classes be instantiated?

abstract class in java is mainly designed for giving abstract method i.e declarations alone, Instantiation is a process by which jvm allocates memory for that. But only with the method declaration jvm will not know how much memory should give for the abstract method. So abstract classes are no need to instantiate before the method implementation, The concrete class which extends the abstract class, will provide method implementation at that time only abstract class constructor will run


What can be declared in an abstract class?

Abstract classes are to be extended until to a concrete class.Can have both abstract & non abstract methods.An Abstract class can not be instantiated.A non abstract class can be extended to an abstract class.If At least one abstract method present in a class then that class must be abstract.abstract & final modifiers can never be together.abstract classes can have both abstract methods & non abstract methods.


What is abstract class and abstract method?

An Abstract method is one that has only a method declaration and no method definition. Similarly an abstract class is one that has one or more abstract methods. You can declare an abstract class or methods by using the keyword abstract in the class definition. Ex: public abstract class TestAbsClass { abstract void method1(); } Any class that extends this abstract class must provide implementation to the method "method1" or else it would have to be abstract as well.


Is abstract data type a structured data type?

Abstract is not a datatype but a modifier. Abstract can be used in 2 places: Methods: If a method is termed abstract it means that the current class does not provide an implementation for this method and the first concrete subclass will do the same. Classes: Any class that has one or more abstract methods has to be abstract. If a class is abstract it means that the implementing class has to provide an implementation for one or more of the abstract methods of this class.


When do you declare a method or class abstract?

public abstract class class_namne{ public abstract void method() {} }


Can you declare final method in abstract class?

Yes, you can declare a final method in an abstract class. However, that method cannot be abstract itself.


What is an abstract factory class?

An abstract factory class is a class which has an abstract method to create an object.


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


Explain the meaning of abstract keyword in relation to classes and 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.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.


How do you declare class as an abstract?

//We Declare an abstract class as-abstract class Car{}//Example of an abstract methodabstract void hondaCity(); //no method body and abstract//Example of Abstract class that has an abstract methodabstract class Car{abstract void run();}class HondaCity extends Car{void run(){System.out.println("runs smartly");}public static void main(String args[]){Car obj = new HondaCity();obj.run();}}//OUTPUT will be-runs smartly


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.


Does abstract class contain the definition of non abstract method in java?

yes,abstract class can have non abstract methods,even it can have all non abstract method


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()"


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.


What is abstract data type in?

Abstract is the data type which can be used at method and class level... The abstract keyword which we used at method level makes that method as abstract means not giving implementation for that method.. the abstract keyword which used at the class level , restrict developers not to create the object of that class.


What is an abstract method?

An abstract method is a method, in object-oriented software, of an abstract class which has to be implemented by all subtyping classes.


What is concrete method?

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


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

Yes. But cannot extend both of them at the same time. Meaning you can extend only one class at a time and that class can be abstract class or concrete class.


What is difference between concrete class and abstract class?

In general programming terms, a concrete class is one which can be instantiated, while an abstract class can only be instantiated via a fully implemented subclass.


What is the concrete method 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.


Still have questions?

Trending Questions
Previously Viewed
Unanswered Questions