wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract class" Watch "Abstract class" New topic
Author

Abstract class

Hitesh chaudhary
Greenhorn

Joined: Jul 20, 2007
Posts: 3
Hi, All
Can we instantiate an Abstract class?

I want to create an instance of Abstract class......
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by Hitesh chaudhary:

Can we instantiate an Abstract class?
I want to create an instance of Abstract class......


You could have got better responses if would have posted in correct forum.

You cannot instantiate an abstract class.


Rahul Bhattacharjee
LinkedIn - Blog
Hitesh chaudhary
Greenhorn

Joined: Jul 20, 2007
Posts: 3
then.......what is this code for.........

abstract class Manoj {

public abstract void makeTea ();

public static Manoj getInstance () {

return new Manoj() {

public void makeTea () {
System.out.println("This is from makeTea method");
}
};
}
}

public class Test {

public Test(){

Manoj manoj=Manoj.getInstance();

manoj.makeTea();

}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

new Test();

}
}
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
Hey Hitesh!!!

As per i think you are not instantiating here
a abstract class,

bcoz instantiation takes place
only by using the new keyword than preeceded by name of
class.........


One more thing to say is abstract class can never
be instantiated ,it can only be extended and using
inheritance we can implement the methods of abstract
according to our usage...ie we can change the defination of the method as per our requirement......


i hope it helps.............
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by Hitesh chaudhary:
Can we instantiate an Abstract class?


Come on, mate. Beginner question. CarefullyChooseOneForum


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Abstract class
 
Similar Threads
HttpServlet class
ABSTRACT
A question about container!
usage of a class
A mock question