Calling a subclass attribute from the main class using Visual Code Java

squirosv

So I can run my code from cmd, I edit using sublime text, but now I´m required to use Visual Code Studio and this software can´t seem to call any subclass porperties from the main method, Visual Code can't seem to handle this line: (Healer)n.get(i)).getHealer()

When I use the subclass getter it doesnt give an error message, however when I try to create an object for the subclass I get the following: "The public type Healer must be defined in its own file"

// n is an ArrayList with objects and this iteration is in the superclass

for(int i = 0; i<= n.size()-1; i++){
   if(Healer.class.isInstance(n.get(i))){
          System.out.println(((Healer)n.get(i)).getHealer());
   }
}

// and here's the constructor for the subclass that I'm calling from the superclass

public class Healer extends Hero{
    int healer;

    Healer(String c, String a, String b, int d, int e, int o){
        super(c,a,b,d,e);
        this.setHealer(o);
    }
    public void setHealer(int o){
        this.healer = o;
    }
    public int getHealer(){
        return healer;
    }
}
Code-Apprentice

This has nothing to do with Visual Studio Code and everything to do with the rules of Java. The error message is very clear about what you need to do:

The public type Healer must be defined in its own file

Either put class Healer in its own file or remove the public modifier.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

using subclass attribute in the main class in python

From Dev

Calling function from a class from the main code

From Dev

Calling Main Method in Java Class From JSP

From Java

Java: calling a super class' protected method from a subclass - not visible?

From Dev

Java: calling subclass implementation of abstract base class method from base class itself but with subclass instance

From Dev

Calling a function in main class from different class in java

From Dev

NSNotificationCenter calling methods from super class or subclass?

From Dev

Calling a function from a class in main

From Dev

Calling methods of a Java subclass using Jython

From Java

Java: Calling super.getClass() from subclass

From Java

Calling superclass from a subclass constructor in Java

From Dev

Calling a class from another class with main method

From Dev

Calling Java class from C++ code on Raspberry Pi

From Dev

Passing a calling class into a subclass and calling a method from it when the subclass has completed a job

From Dev

Java 11 syntax error calling class properties (Car) from another class (Main)

From Dev

Implicitly calling a method in a class from main

From Dev

Calling a default method from Interface in Main Class

From Dev

Calling a class function from main with parameters

From Dev

Java: calling a class variable and assigning it a value in the main

From Dev

ServiceStack - Attribute knows what class it is calling from?

From Dev

Subclass calling Base Class constructor then using instance method of Base Class in Subclass Arduino C++

From Dev

Why is format method from NumberFormat class calling subclass format method?

From Java

Calling methods from a super class when a subclass is instantiated

From Dev

How to pull variables of the main class from a subclass in django

From Dev

Problem of Returning the main class instead of the subclass JAVA android

From Dev

How to create subclass such that it's attribute values are not overridden from parent class?

From Dev

Java Retrieve Subclass Objects from Parent Class

From Java

Java: Get instance of super class from subclass

From Java

Issue in calling Python code from Java (without using jython)

Related Related

  1. 1

    using subclass attribute in the main class in python

  2. 2

    Calling function from a class from the main code

  3. 3

    Calling Main Method in Java Class From JSP

  4. 4

    Java: calling a super class' protected method from a subclass - not visible?

  5. 5

    Java: calling subclass implementation of abstract base class method from base class itself but with subclass instance

  6. 6

    Calling a function in main class from different class in java

  7. 7

    NSNotificationCenter calling methods from super class or subclass?

  8. 8

    Calling a function from a class in main

  9. 9

    Calling methods of a Java subclass using Jython

  10. 10

    Java: Calling super.getClass() from subclass

  11. 11

    Calling superclass from a subclass constructor in Java

  12. 12

    Calling a class from another class with main method

  13. 13

    Calling Java class from C++ code on Raspberry Pi

  14. 14

    Passing a calling class into a subclass and calling a method from it when the subclass has completed a job

  15. 15

    Java 11 syntax error calling class properties (Car) from another class (Main)

  16. 16

    Implicitly calling a method in a class from main

  17. 17

    Calling a default method from Interface in Main Class

  18. 18

    Calling a class function from main with parameters

  19. 19

    Java: calling a class variable and assigning it a value in the main

  20. 20

    ServiceStack - Attribute knows what class it is calling from?

  21. 21

    Subclass calling Base Class constructor then using instance method of Base Class in Subclass Arduino C++

  22. 22

    Why is format method from NumberFormat class calling subclass format method?

  23. 23

    Calling methods from a super class when a subclass is instantiated

  24. 24

    How to pull variables of the main class from a subclass in django

  25. 25

    Problem of Returning the main class instead of the subclass JAVA android

  26. 26

    How to create subclass such that it's attribute values are not overridden from parent class?

  27. 27

    Java Retrieve Subclass Objects from Parent Class

  28. 28

    Java: Get instance of super class from subclass

  29. 29

    Issue in calling Python code from Java (without using jython)

HotTag

Archive