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

Overriding Method  RSS feed

 
asha ganapathy
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My program looks like this..

abstract class AbstractMain{
public abstract void importantMethod();
public void importantMethod2(){
int i=10;
System.out.println("This is importantMethod2 in
AbstractMainclass");
}
}

public class Main extends AbstractMain{
public static void main(String[] args){

AbstractMain m = new Main();
m.importantMethod();
m.importantMethod2();
}
public void importantMethod(){
System.out.println("This is importantMethod of Main class");
}
public void importantMethod2() {
//here i want to use the local variables of AbstractMain() class
System.out.println("This is importantMethod2 of Main class");
}
}

Is it possible to use the local variable of importantMethod2()in the overridden method?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by asha ganapathy:
Is it possible to use the local variable of importantMethod2()in the overridden method?

No. A local variable is just that: local. If you want a variable that methods can share, declare an instance variable or a static class variable.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!