Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of objects in Jython

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you the "sample analysis of objects in Jython", the content is simple and clear, hoping to help you solve your doubts, let the editor lead you to study and study the "sample analysis of objects in Jython" this article.

Objects in Jython

Jython is an object-oriented language that fully supports object-oriented programming. Objects defined by Jython have the following properties:

Identity: each object must be unique and can be tested. Jython supports is and is not testing to achieve this.

2, state: each object must be able to store state. Jython provides properties (also known as fields or instance variables) to do this.

3, behavior: each object must be able to manipulate its state. To do this, Jython provides a method.

Notice that the built-in function id (object) returns a unique integer identity value. Thus, the expression x is y is equivalent to id (x) = = id (y).

Objects in Jython-- OOP support

Jython includes the following features to support object-oriented programming:

Create objects based on classes: the Jython class is a template for creating objects. An object is a data structure with associated behavior.

Polymorphic inheritance: Jython supports single inheritance and multiple inheritance. All Jython instance methods are polymorphic (or virtual) and can be overridden by subclasses.

Encapsulating hidden data: Jython allows (but does not require) hidden properties, so it can only be accessed outside the class through the methods of the class. Class implements a function (called a method) that modifies data.

Objects in Jython-- define classes

Defining a class is like defining a module in which variables and functions can be defined. Unlike the Java language, Jython allows any number of public classes to be defined in each source file (or module). So in Jython, modules are very much like packages in the Java language.

In Jython, we use class statements to define classes. The format of the class statement is as follows:

Class name (superclasses): statement

Or

Class name (superclasses): assignment: function:

When defining a class, you can choose to provide zero or more assignment statements. They create class properties shared by all instances of this class. Zero or more function definitions can also be provided. The way they are created. The parent class list is optional. We will discuss the parent class later in this tutorial.

Class names should be unique in the same scope (module, function, or class). The class name is actually a variable bound to the body of the class (similar to all other assignments). In fact, you can define multiple variables to refer to the same class.

Objects in Jython-- create class instances

A class is used to contain class (or shared) properties or to create an instance of the class. To create an instance of a class, simply treat the class as a function call. You don't need to use the new operator as you do in C++ or the Java language. For example, for a class

Class MyClass: pass

The following statement creates an instance:

X = MyClass () these are all the contents of the article "sample Analysis of objects in Jython". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report