This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question from Dan chisholm on abstract class  RSS feed

 
Rekha Gaikwad
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abstract class A { // 1
private abstract void m1(); // 2
private abstract class B {} // 3
private class C extends B {} // 4
}

Which line results in a compile-time error?

a. 1
b. 2
c. 3
d. 4
e. None of the above.


Answer on site mention is b


But isn't the answer 'a' is wrong?? Bcz abstract method is declared as private so we can not inherit is so there is no implementation..

and why answer B is correct?
 
Steve Sugden
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have the right reason -
"Bcz abstract method is declared as private so we can not inherit is so there is no implementation.."

You can't have an abstract private method because the concrete class can't override that method (an therefore implement it).

So line 2 (b) is where the compiler falls over. Like this

---------- Capture Output ----------
> "C:\j2sdk1.4.2_05\bin\javac.exe" C:\javawork\A.java
C:\javawork\A.java:2: illegal combination of modifiers: abstract and private
private abstract void m1(); // 2
^
1 error
> Terminated with exit code 1.
 
Arvind Giri
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Rekha,
You seem right however the root of that error is in line 2. So (b) is right answer.

Am I right?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!