Friday, March 6, 2009

abstract class with out abstract methods



package funds;
// abstract class with out any abstract method
/* Sun people flow the same thing In case of Servlet API HttpServlet
is abstract class but there is no abstract methods in that class */

abstract class Absclass {
void m1()
{
System.out.println("this m1 impl");
}
void m2()
{
System.out.println("this m2 imple");
}
}

public class WithoutAbstract extends Absclass
{
public static void main(String arg[])
{
WithoutAbstract w=new WithoutAbstract();
w.m1();
w.m2();
}
}

output:
this m1 impl
this m2 imple



6 comments:

Anonymous said...

Good program...

Anonymous said...

simple but impressive program

Anonymous said...

good work...

Anonymous said...

Abstract class should contain atleast one abstract method.. but there is no abstract method.. u gave example programme ok.. can any one explain it..?? y it is declared as abstract class without having any abstract method..??

Thanks,
Bujji

LakshmiNarayana Gorantla said...

See....If declare any class as a abstract class we can't able to create the object to that class.To call the methods inside the abstract we should have to extends the abstract class.
Ex: HttpServlet class in servlet API.
we can only extends the HttpServlet class to cal the methods,we can't create object to that class to cal the method.

Anonymous said...

when ever we dont want create any object manuvally, means want to create object by some other resource like server then that time we can declare class as abstract without abstract method.for example as part of HttpServlet we cant create object, server only loads and create object. these type of scnarios we can create.

thanks,
ramaiah pillala.

Post a Comment