Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Java Inheritance: Child class not executing

I was practicing inheritance in Java, and faced the following issue:

Code for parent class:

public class FEB7 {
String address,name;
void get(String n, String a){
    name = n;
    address = a;
}
void show(){
    System.out.println("name is "+name);
    System.out.println("address is " + address);
}
public static void main(String args[]) {
    // compile time poly is method overloading, we will look at runtime poly
    FEB7 obj = new FEB7();
    obj.get("name1","address1");
    obj.show();
} }

Code for child class:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public class FEB8 extends FEB7 {
String regno;

void get(String r) {
    regno = r;
}

void showreg() {
    System.out.println("regno is " + regno);
}

public static void main(String args) {
    FEB8 obj1 = new FEB8();
    obj1.get("name2", "address2");
    obj1.get("regno1");
    obj1.show();
    obj1.showreg();
}}

Both are separate .java files. When i try to execute the parent class file, it works but for some reason i cannot even run the child class. The following message is there:

The file FEB8.java is not executable. please select a main class you want to run

How do i solve this issue?

>Solution :

The main method in FEB8 has String args as the argument instead of String args[]. Change it to args[] and try again.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading