0

Line: 2, Column: 3 Method does not exist or incorrect signature: void show() from the type Child2.

Above is the error im getting. How can I rectify it?

public Virtual class Parent2 {
public string name;
    public string branch;
    public virtual void show(){
        name='kiran';
        branch='vijayawada';
    }
    public void invoke(){
        system.debug('Name:'+name);
        system.debug('Branch:'+branch);
    }

}
public class Child2 Extends parent2 {
    public integer age;
    public String phone;
    public override Void Show(){
        name='ravi';
        age=90;
        branch='mpl';
        phone='1111';
    }
    public void Display(){
       system.debug('Name:'+name);
       system.debug('Age:'+age);
       system.debug('Branch:'+branch);
       system.debug('Phone:'+phone);
    }
}

Execute:

Child2 c=new Child2();
C.show();
C.display();
7
  • your code is perfectly running at my DE – Santanu Boral May 10 '18 at 4:08
  • What could be the problem? – Hemanth May 10 '18 at 4:18
  • Can you provide more details as where/when are you receiving this error? Is it compile time, runtime, in a test class? – Jayant Das May 10 '18 at 4:20
  • It is in compile time Execute Anonymous error – Hemanth May 10 '18 at 4:56
  • It's working at my end...just executed my developer console....only difference I can see your method name is started with cap S...and your calling with lower s...but case-sensitivity should not be problem in apex.... Are your running your code in Dev Console? – Ayub May 10 '18 at 6:24
1

I believe the issue is due to our use of the Virtual keyword in the Parent2 definition. According to the documentation, classes defined in Execute Anonymous are considered virtual by default.

Be removing the virtual keyword from the class definition, I was able to get this to compile and run as expected in my environment.

public class Parent2 {
public string name;
    public string branch;
    public virtual void show(){
        name='kiran';
        branch='vijayawada';
    }
    public void invoke(){
        system.debug('Name:'+name);
        system.debug('Branch:'+branch);
    }

}
public class Child2 Extends parent2 {
    public integer age;
    public String phone;
    public override Void Show(){
        name='ravi';
        age=90;
        branch='mpl';
        phone='1111';
    }
    public void Display(){
       system.debug('Name:'+name);
       system.debug('Age:'+age);
       system.debug('Branch:'+branch);
       system.debug('Phone:'+phone);
    }
}

Child2 c=new Child2();
C.show();
C.display();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.