Can i have abstract class with no abstract methods?
Answers were Sorted based on User's Feedback
Answer / poonam
Yes, we can have abstract class without abstract method.
Best example is HttpServlet
Is This Answer Correct ? | 198 Yes | 11 No |
Answer / santosh
yes we can have concreate method in the abstract class
Is This Answer Correct ? | 42 Yes | 4 No |
Answer / mandeswara rao
yes, we can.To prevent a class from directly creating
objects, better declare them as abstract classes.
Eg: HttpServlet
Is This Answer Correct ? | 37 Yes | 2 No |
Answer / aravind
yes we can have abstract class with out a abstract methods
but when u have a single abstarct method u r class must and
should be declared as Abstarct.
Is This Answer Correct ? | 27 Yes | 4 No |
Answer / mohan sahu
An abstract class without any abstract methods should be a
rare thing and you should always question your application
design if this case arises. Normally you should refactor to
use a concrete superclass in this scenario.
One specific case where abstract class may justifiably have
no abstract methods is where it partially implements an
interface, with the intention that its subclasses must
complete the interface. To take a slightly contrived
motoring analogy, a Chassis class may partially implement a
Vehicle interface and provide a set of core methods from
which a range of concrete Vehicle types are extended.
Chassis is not a viable implementation of a Vehicle in its
own right, so a concrete Car subclass would have to
implement interface methods for functional wheels, engine
and bodywork.
Is This Answer Correct ? | 11 Yes | 1 No |
Answer / manish kushwaha
HI All,
In Java there is very lovely concept related to Abstract
Class, keep this concept always in your mind i.e.
1) A class can be abstract "without any abstract method".
2) But if a single method is abstract you need to declare
your class as abstract this is mandatory but if class is
abstract then its not mandatory to have abstract methods
as mentioned above.
Is This Answer Correct ? | 6 Yes | 2 No |
yes,please find the below example.
abstract class AbstractClass1 {
public void method1(){
System.out.println("inside method1...");
}
}
class AbstractClass2 extends AbstractClass1{
public void method2(){
System.out.println("inside method2...");
}
}
public class AbstractDemo {
public static void main(String[] args) {
AbstractClass2 a = new AbstractClass2();
a.method1();
a.method2();
}
}
Is This Answer Correct ? | 6 Yes | 2 No |
Answer / saubhik
Yes, we can do it undoubtedly, in that case we restrict it
to make an object of it. Example.- HttpServlet
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / darkeye
I certainly agree with Manish Kushwaha You can have abstract class without any abstract method but if you have a single abstract method you are suppose to make that class abstract
This is what Sun says :
" An abstract class is a class that is declared abstract—it may or may not include abstract methods" (http://java.sun.com/docs/books/tutorial/java/IandI/abstract.html)
Is This Answer Correct ? | 1 Yes | 1 No |
How can I become a good programmer?
Which methods cannot be overridden in java?
How to convert string to byte array and vice versa?
as we know a static method could access static data and static method only. then how could main method call the object of aclass which is not static and other non static data
import java.io.*; class Demo { public static void main(String args[]) { File f=new File("1234.msg"); String arr[]=f.list(); System.out.println(arr.length); } }
Is null false in java?
When we r go to abstract class and when we go to Interface? i have confusion this question while in interview plz clarify
What is a stack class in java ?
0 Answers Akamai Technologies,
Difference between string, string builder, and string buffer?
What is a string what operation can be performed out with the help of a string?
What is final keyword?
What is the difference between a synchronized method and a synchronized block?