Tasks studies - laboratory
Brief Introduction
Class members can be static
or non-static
.
Non-static members are always associated with the existence of an object (fields correspond to object elements, methods must be called on an object, and are messages to the object).
Static members (fields and methods) are shared across all objects and:
static
specifier,Note: Static methods must not reference non-static members of the class (as the object may not exist). However, they can refer to other static members.
Outside the class, static members can be accessed in two ways:
ClassName.MemberName
If an object exists: the same way as for non-static members (note: this is misleading and not recommended).
Create a class Figury
. Add the following code to it and test its functionality. Note that the static methods PoleKola
and ObwodKola
use other static methods from the Math library, which is also a class. Add additional static methods inside the class to calculate the following shapes: square
, rectangle
, cone
, cylinder
.
Test and describe the functionality of the following source code.
Create a class Complex
implementing the structure of complex numbers. Add the following static methods to the class for operations on complex numbers:
Also, add methods that return the value of a complex number as a string (String
) in the following formats: