aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes abstract Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "abstract" Watch "abstract" New topic
Author

abstract

Dimple Kaushik
Ranch Hand

Joined: Nov 19, 2003
Posts: 49
From Khalid A. Mughal:
Which one of the following class definitions is a valid definition of a class that cannot be instantiated?
Select the one correct answer.
a.class Ghost {
abstract void haunt();
}
b.abstract class Ghost {
void haunt();
}
c.abstract class Ghost {
void haunt() {};
}
d.abstract Ghost {
abstract void haunt();
}
e.static class Ghost {
abstract haunt();
}
given ans: c
Why not b?
Thanks.
Cathy Song
Ranch Hand

Joined: Aug 24, 2003
Posts: 270
Hi Dimple,
a.class Ghost { //class not abstract
abstract void haunt();
}
//will NOT compile, not valid

b.abstract class Ghost {
void haunt(); //abstract keyword required
}
//will NOT compile, not valid
c.abstract class Ghost {
void haunt() {};
}
//ok
d.abstract Ghost { //class keyword missing
abstract void haunt();
}
//will NOT compile, not valid
e.static class Ghost { //must be abstract not static
abstract haunt();
}
//will NOT compile, not valid
Thus c is the only right answer. Hope this helps.
toshi murayama
Greenhorn

Joined: Nov 14, 2003
Posts: 1
Originally posted by dimple kaushik:
From Khalid A. Mughal:
Which one of the following class definitions is a valid definition of a class that cannot be instantiated?
Select the one correct answer.
b.abstract class Ghost {
void haunt();
}

if ,
abstract class Ghost {
void haunt(){}
//void haunt();
}
can compile.
But, if you want to a class never be instantiated,
you should make all constructer "private".
Not use abstract class.
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
The question is perfectly correct and unambiguous: abstract classes can never be instantiated. A class with all private constructors can still be instantiated - objects of its type can be created:

If all constructors are private, such a class cannot be instantiated outside of its scope. java.lang.Math is a good example on that.
Dimple Kaushik
Ranch Hand

Joined: Nov 19, 2003
Posts: 49
Thnx everybody.
I'm clear with the private constructor thing.
Somehow i thought that class declared abstarct is good enough for not being instantiated as in case b.
I have one more question sometimes i get an error
cyclic inheritance involving <someclass>
What does it really mean??
Dimple Kaushik
Ranch Hand

Joined: Nov 19, 2003
Posts: 49
I tired some examples and figured out 3 cases.
1.class A extends A// trying to extend it's own class
2.class A extends B{
class B{} // innerclass inheritance
}
3.class A extends B{}
class B extends A{}// cyclic inheritance
Any other casses?
Just want to make sure.
[ November 20, 2003: Message edited by: dimple kaushik ]
priya vinay
Greenhorn

Joined: Nov 14, 2003
Posts: 21
Originally posted by dimple kaushik:
I have one more question sometimes i get an error
cyclic inheritance involving <someclass>
What does it really mean??
I tired some examples and figured out 3 cases.
1.class A extends A// trying to extend it's own class
2.class A extends B{
class B{} // innerclass inheritance
}
3.class A extends B{}
class B extends A{}// cyclic inheritance
Any other casses?
Just want to make sure.
[ November 20, 2003: Message edited by: dimple kaushik ]

I never get this type of error before.
Sometimes its good to learn new errors
[ November 20, 2003: Message edited by: priya varma ]
Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104
1.class A extends A// trying to extend it's own class
2.class A extends B{
class B{} // innerclass inheritance
}
3.class A extends B{}
class B extends A{}// cyclic inheritance
Any other casses?

I am wondering, what is cyclic inhertiance ? could any one explain..


Anbudan & Mahalo,<br />Arul<br /> <br />-Not a sun certified Java professional :-)
Dimple Kaushik
Ranch Hand

Joined: Nov 19, 2003
Posts: 49
Originally posted by Arul kumar:

I am wondering, what is cyclic inhertiance ? could any one explain..

Arul,
I was trying some code in inheritence and in the process i came through this error 'cyclic inheritence involving <classname> which i never heard or read anywhere before.
As far as i know cyclic inheritance as the name sounds is..
1)extending it's own class.
class A extends A {.....
2)extending one of it's inner class
class A extends B{
class B{
//...
}
//...
}
3)extending a class which extends the original class
class A extends B{
//....
}
class B extends A{
//....
}
Even i'm waiting for someone to explain or provide me some supporting stuff or else i may feel like COLUMBUS here.
Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104
hello dimple,
"I am wondering, what is cyclic inhertiance ? could any one explain"
The reason i put this is, all the cases described by you are impossible ones. did u try atleast one case in your program?
As per my knowledge and experience i have never used this type of inheritance. so i was wondering and curios to know about that.
I felt, the privious post, by priya also indicates the same.
Dimple Kaushik
Ranch Hand

Joined: Nov 19, 2003
Posts: 49
I know that all those cases i explained are impossible.
I was just trying to highlight the error i got which i never heard before.
Thanks Anyway.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
The compiler will yield errors for all these cases. Recall that the constructor of a class ends up calling a constructor of the immediate superclass.
class A extends A {.....
A's contructor will call itself producing an endless loop.
class A extends B{
class B{...

A's contructor will call B's contructor. The latter needs an instance of the enclosing class because is an inner class, but you cannot create an instance of the class A without having created first an instance of its superclass B.

class A extends B{
//....
}
class B extends A{
//....

A's constructor calls B's one, but wait! B's constructor calls A's one; thus the result is an endless loop again.


SCJP2. Please Indent your code using UBB Code
 
Don't get me started about those stupid light bulbs.
 
subject: abstract