• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can non abstract methods can access abstract methods

 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am preapring for Java interview, I came across this question.
Q) when you declare a method as a abstract, can other non abstract methods can access it?
Ans)Yes,other non abstract methods can access a method that you declare as a abstract.

I think this anwer is wrong.

Q1)Please correct me if i am wrong?





 
Henry Wong
author
Marshal
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try...




And "access" is the wrong word -- as you technically can't access anything that doesn't exist -- maybe "allowed to call" is better.

Henry
 
Oguzhan Acargil
Greenhorn
Posts: 6
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to google Template pattern...

A subclass implements abstract methods. In order to access non abstract methods in an abstract class, you have to intiate it with a subclass. Thats way there is no problem.

I wish it is clear
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yesss.....Non-abstract method can call Non-abstract method

Reason :- Compiler ensures that we cannot create an object for an abstract class.
This means whenever we could call that non-abstract method, it would be called only from the class which extends the abstract class.
In that case , the class which would extend the abstract class has to implement the abstract method.
So it is possible to call it !!!


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic