Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract class

 
Hitesh chaudhary
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, All
Can we instantiate an Abstract class?

I want to create an instance of Abstract class......
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hitesh chaudhary
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Hitesh chaudhary:
Can we instantiate an Abstract class?


Come on, mate. Beginner question. CarefullyChooseOneForum
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic