Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mock exam question doubt

 
rajesh vasireddy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Replace two modifiers that appears in the Single class to make the code to compile.
Note: Three modifiers will not be used and four modifiers in the code will remain unchanged.
options given are...
final
protected
private
abstract
static
......................................................................
public class Single {
private static Single instance;
public static Single getInstance() {
if(instance==null)
instance=create();
return instance;
}
private Single(){}
protected Single create(){return new Single();}
}

class SingleSub extends Single{}
 
N.Senthil Kumar
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hey Pal, You can replace the modifiers in the line 9 and 10 with protected and static respectively.

Make the constructor protected to make it visible to the SingleSub and you can replace protected to static in line 10 to make the code to compile, since in line 10 non-static create() is attempted to use in a static method getInstance(). either you can add static with protected in the line 10. but the ques is about replacing. Hence you can replace this two. to make you code to compile.
 
rajesh vasireddy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much buddy...

 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4589
302
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And please QuoteYourSources
 
rajesh vasireddy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Devaka Cooray,

Your Test Simulators are good.
Thank you for your valuable answer sir.

 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4589
302
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this from ExamLab?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic