Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Please clarify this  RSS feed

 
Manish Jaju
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will happen in the case below

class A
{
int a(int b)
{
//somecode
}
}

class B extends A
{
byte a(int b)
{
//somecode
}
}


public class C
{
B b=new B();
b.a(10);
}


What will happen in case a(10) be called, Which method will it call??
 
Vijayendra V Rao
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Manish Vyas:
What will happen in the case below

class A
{
int a(int b)
{
//somecode
}
}

class B extends A
{
byte a(int b)
{
//somecode
}
}


public class C
{
B b=new B();
b.a(10);
}


What will happen in case a(10) be called, Which method will it call??


First tell me...are you able to compile this code?!!!
 
durga kar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code cannot compile. You have to have a default base calss constructor.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code in C must be in a block.

You can't override a method returning int with a method returning byte.

You must have a return statement in each method returning byte or int.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!