• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Abstract class

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question is from the mock exam http://jquest.webjump.com. The correct answer is given as 'a'. But I think both 'a' & 'c' are correct. Please advise me.

You are creating a ToolBase class which will be extended by other programmers. The ToolBase class contains a single abstract method, createTool.
Which of the following statements are true?
Ans :
a. The ToolBase class must be declared abstract
b. The ToolBase class must not be declared final
c. The following variable declaration is illegal in any context "ToolBase myTB;"
 
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I can tell the correct answers are a & b. The class has to be abstract because it contains an abstract method. B is correct because an abstract class cannot be final, and it says that the class is being made so programmers are able to extend it. C is a bit ambiguous, but I don't see how you could have a reference to an object that is a class that isn't even defined yet.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ToolBase tb = new ChildOfToolBase();
 
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A and B are correct.
1. If a class has an abstract method, then the class must be defined abstract.
2. An abstract class can have final methods, but a final class can't have abstract methods.
3. You can't not instantiate an abstract class, but you can create an object reference (like Thomas's post).
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C is also correct. There is nothing wrong with creating a variable defintion such as:
MyAbstractClass mac;
You can even do this:
MyAbstractClass mac = new MyAbstractClass() {
... anonymous definition of abstract methods
};
Example:
Runnable r = new Runnable() {
public void run() { // implementing code }
};
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a. The ToolBase class must be declared abstract TRUE
b. The ToolBase class must not be declared final TRUE
c. The following variable declaration is illegal in any context "ToolBase myTB; FALSE


Only a&b should be correct answers not c.

------------------
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
c is also perfectly correct is the ToolBase class is abstract and not an interface
i was able to compile
abstract class TestAbstract{
abstract void f();
TestAbstract t;
}
Thanks
Vivek
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, you're all confusing me. C says that it's illegal. Because you can do this (TestAbstract t) then C is not a correct answer. The answer's A and B, right?

[This message has been edited by Dave Terrian (edited April 23, 2001).]
 
vivek bawge
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the confusion that arised because i concentrated more on Thomas's reply.
Yes, I am pretty positive that the answers are A and B only and C is false because such a declaration is legal indeed
Thanks,
Vivek
 
Does this tiny ad smell okay to you?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic