Calling methods of a Java subclass using Jython

Curious

I have this Java class,

public class sample {
        public Integer foo1(Integer x){
            return x+5;
        }
    }
class SubClass extends sample{

    public Integer foo2(Integer x){
        return x+100;
    }
}

And with Jython I want to call foo2 of the class SubClass. I ended up with the following Python code,

import SubClass, sample
java_file = SubClass()
print java_file.foo2(3)

But running the Python code returns this error,

AttributeError: 'SubClass' object has no attribute 'foo2'

I also want to print the super class of a class and it's signature including the attributes like public, abstract, etc.

Is there a way to do this? Thanks!

Stephan

You have to first create a instance... the invoke the method... like the following example:

Beach.java

public class Beach {

    private String name;
    private String city;


    public Beach(String name, String city){
        this.name = name;
        this.city = city;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

}
Using Beach.java in Jython

>>> import Beach
>>> beach = Beach("Cocoa Beach","Cocoa Beach")
>>> beach.getName()
u'Cocoa Beach'
>>> print beach.getName()
Cocoa Beach

You can read more here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

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

From Dev

Jython - Calling Python Class in Java

From Dev

Calling superclass methods from a subclass

From Dev

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

From Dev

Using variables for creating objects and calling methods in Java

From Dev

Using "super" keyword or using a superclass instance when calling superclass methods locally in a method from subclass?

From Java

Calling awt Frame methods from subclass

From Dev

NSNotificationCenter calling methods from super class or subclass?

From Dev

Delegate methods not calling in UITextField custom subclass

From Dev

Using the super class paramater for the subclass methods in the subclass

From Dev

Access methods from Java project in Jython

From Dev

Calling Function in MainClass using SubClass

From Java

Implementing abstract methods in a subclass in Java

From Dev

XPages - Calling Java methods

From Dev

Calling the methods in java

From Dev

Calling Java Methods in XSLT

From Java

Calling multiple methods in Java

From Java

Calling the methods in a class in Java

From Dev

Calling methods on objects Java

From Java

Java question (calling methods with parameters) using UnboundID LDAP SDK api

From Dev

calling different methods of same class using multi threading in java

From Dev

do you need jython for calling a python script from java?

From Java

Calling methods from a super class when a subclass is instantiated

From Dev

Calling subclass methods from superclass in a vector C++

From Java

Java: Calling super.getClass() from subclass

From Java

Calling superclass from a subclass constructor in Java

From Dev

calling subclass method after initialising to parent java

From Dev

Java Inheritance: Calling a subclass method in a superclass

From Dev

Java Inheritance: Why is it not calling the method of the subclass?

Related Related

  1. 1

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

  2. 2

    Jython - Calling Python Class in Java

  3. 3

    Calling superclass methods from a subclass

  4. 4

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

  5. 5

    Using variables for creating objects and calling methods in Java

  6. 6

    Using "super" keyword or using a superclass instance when calling superclass methods locally in a method from subclass?

  7. 7

    Calling awt Frame methods from subclass

  8. 8

    NSNotificationCenter calling methods from super class or subclass?

  9. 9

    Delegate methods not calling in UITextField custom subclass

  10. 10

    Using the super class paramater for the subclass methods in the subclass

  11. 11

    Access methods from Java project in Jython

  12. 12

    Calling Function in MainClass using SubClass

  13. 13

    Implementing abstract methods in a subclass in Java

  14. 14

    XPages - Calling Java methods

  15. 15

    Calling the methods in java

  16. 16

    Calling Java Methods in XSLT

  17. 17

    Calling multiple methods in Java

  18. 18

    Calling the methods in a class in Java

  19. 19

    Calling methods on objects Java

  20. 20

    Java question (calling methods with parameters) using UnboundID LDAP SDK api

  21. 21

    calling different methods of same class using multi threading in java

  22. 22

    do you need jython for calling a python script from java?

  23. 23

    Calling methods from a super class when a subclass is instantiated

  24. 24

    Calling subclass methods from superclass in a vector C++

  25. 25

    Java: Calling super.getClass() from subclass

  26. 26

    Calling superclass from a subclass constructor in Java

  27. 27

    calling subclass method after initialising to parent java

  28. 28

    Java Inheritance: Calling a subclass method in a superclass

  29. 29

    Java Inheritance: Why is it not calling the method of the subclass?

HotTag

Archive