• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

override Question about abstract class.

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
a. The ToolBase class must be declared abstract.
b. Classes extending ToolBase must not be declared
abstract.
c. The ToolBase class must not be declared final.
d. The following variable declaration is illegal in any
context "ToolBase myTB;"

concern the question I think the ToolBase must be
declare abstract (because it has a abatract method).as a
result it could not be instance ,so ToolBase myTB
(which mean to ToolBase myTB=new ToolBae() will
compile error.
my ans :a,c;
but given ans: acd
somebody correct me if I am wrong.
Good regard.

 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gong James:
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?
a. The ToolBase class must be declared abstract.
b. Classes extending ToolBase must not be declared
abstract.
c. The ToolBase class must not be declared final.
d. The following variable declaration is illegal in any
context "ToolBase myTB;"

concern the question I think the ToolBase must be
declare abstract (because it has a abatract method).as a
result it could not be instance ,so ToolBase myTB
(which mean to ToolBase myTB=new ToolBae() will
compile error.
my ans :a,c;
but given ans: acd
somebody correct me if I am wrong.
Good regard.


Yeah the answer is a,c,d
Abstract class can have its own reference
They do even have constructors( component())
But they cant be instantiated though
Many times you see abstract class being parent and
it is legitimate to have a reference of parent class referring to this concerete subclass
Ragu
 
Ranch Hand
Posts: 5415
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
correct ans are:
a,c
d can not be correct as it says:
it is illegal to ...........
ToolBax tb;
But it is legal as you can have reference variable of abstract class.
so the true options are a,c

------------------
Regards
Ravish
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
d. The following variable declaration is illegal in any
context "ToolBase myTB;"
d. it is legal, see below :
------------------------------
public class Verify {
public static void main(String [] args){
ToolBase myTB=new ChildToolBase();
myTB.amethod();
}
}
abstract class ToolBase {
abstract void amethod();
}
class ChildToolBase extends ToolBase {
void amethod(){System.out.println("In ChildToolBase");}
}
So I agree with ravish kumar
Correct answers are a,c
Best regards
 
You may have just won ten million dollars! Or, maybe a tiny ad.
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic