Email address:
Password:
SCJP/OCPJP 1.6 certification
Practice Exams and Training
SCJP Online Training » Discussions

abstract class

Can we create object of abstract class in any ways ?

Not directly. But if you have a non-abstract class that extends your abstract class, you can create an object of that non-abstract class.


For example, consider this:


class AbstractDemo {
}

class NonAbstractDemo extends AbstractDemo {
}


You obviously canNOT instantiate AbstractDemo, but you CAN instantiate your non-abstract class:


AbstractDemo obj = new NonAbstractDemo();


What's the point of doing this? - you may ask. The answer is, if you had some (non-private) variables or methods in your AbstractDemo class, your NonAbstractDemo has inherited all of them!

ExamLab © 2008 - 2024