• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Abstract class qustion from khalid book

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which one of the following class defination of a class that cannot be instantiated
Select the one right answer
a) class Ghost{
absract void haunt ();
}
b) abstract class Ghost{
void haunt ();
}
c) abstract class Ghost{
absract void haunt (){};
}
d)
abstract Ghost{
absract void haunt ();
}
e) static class Ghost
{
abstract haunt ();
}
the ans is c i feel if c is correct b is also correct because the method is not implemented we dont need a brace because that is the difference between c and b
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
method in b is not declared as abstract so it does need brace!
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are you sure c is correct?
I think putting brace there will cause a compil error!
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In my book, the answer choices are like this..
Which is legal definition of a class that can't be instantiated?
a)class Ghost{
abstract void haunt();
}
// compiler error since class isn't declared abstract
b) abstract class Ghost{
void haunt();
}
// the method haunt is not implemented (no braces)

c) abstract class Ghost {
void haunt(){};
}

// this is legal definition of the abstract class
so the answer choice c is correct
d)abstract Ghost{
abstarct void haunt();
}
// missing class

hope this helps,
Vanitha.
 
Tosin Adedoyin
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i feel that the braces should not make the difference with answer b absract methods in abstract classes do not have to be implemeted anywway so the brace should not make a diference should it ???
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if a method is not declared abstract in an abstarct class then it should have a body (implentaion) ie the braces.
thats y b is wrong.
if u dont want to provide an implentaion then declare it abstract and use the ; at the end.
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vanitha Sugumaran:
Hi,
In my book, the answer choices are like this..
Which is legal definition of a class that can't be instantiated?
a)class Ghost{
abstract void haunt();
}
// compiler error since class isn't declared abstract
b) abstract class Ghost{
void haunt();
}
// the method haunt is not implemented (no braces)

c) abstract class Ghost {
void haunt(){};
}

// this is legal definition of the abstract class
so the answer choice c is correct
d)abstract Ghost{
abstarct void haunt();
}
// missing class

hope this helps,
Vanitha.


I do totally agree with you but the C coming from Tosin is not exactly the same,
abstract class Ghost{
absract void haunt (){};
}

The method is also declared abstract with braces! And he says that's the good answer. I feel that there is no good answers in his case. Maybe he didn't pay attention when copying? Do you have the same book?
 
Tosin Adedoyin
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry c should have been
absract class Ghost
{
void haunt (){};
}
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic