Questions tagged [class-method]

Methods that are called on a class instead of on an object.

Class methods are methods that are called on a class (compare this to class instance methods, or object methods). Its meaning may vary depending on the programming language: In some languages (e.g. C++, Java), class methods are synonymous with static methods (see section below), which are called with a known class name at compile-time. this cannot be used in static methods.

In some other languages (e.g. Smalltalk, Ruby, Objective-C), class methods are methods that are called on a class object, which can be computed at runtime, there being no difference between calling a method on a regular object or a class object; thus both instance and class methods are resolved dynamically, and there are no "static" methods. Notably, in these class methods, this refers to the class object.

Some languages have both. For example, in Python, one can create class methods and static methods using the classmethod and staticmethod decorators, respectively. The former has access to this (i.e. the instance object, conventionally known as self), while the latter does not.

904 questions
-2
votes
1 answer

Can not watch list 'matrix'

I have a problem with class "CellList", so I want to print list "matrix". But when I print this list, my Pycharm display "[[myfile.Cell object at 0x0034...][myfile.Cell object at 0x0034...],...]" class Cell: def __init__(self, row: int, col:…
-2
votes
2 answers

Calling a name in a method that doesnt exist in the actual context C#

recently I started learning C# by reading books and while using methods to build an app contact i got this issue. I can't understand why the compiler don't recognise the variables of the parameters of the method "Storeinfo" (contact/address/number)…
c.pacheco
  • 7
  • 1
-2
votes
5 answers

Method creation error

I am trying to create a method for my program that, when called, will ask you to press enter to continue. However, BlueJ gives me an error message saying ' expected'. Below is my code Note: the continue class hasn't been fully finished yet. import…
-2
votes
2 answers

I am having trouble printing out an instance method and a class method

So the code I am working with is supposed to check if a number is prime and then I need to print out the result of, whether it is prime? From my instance and class method. I am having trouble because I feel like I set up everything correctly, but I…
-2
votes
1 answer

Object Oriented Programming - Basic informations on Methods with WindowsForm

I studied in programming and graduated in 1998... yeah i'm old LOL Long story made short, I never worked in that field, but decided to get back to it to make myself a membership management program. There is one thing I can't recall about object…
Karen
  • 3
  • 2
-2
votes
1 answer

Python/Tornado - call to classmethod

Given this simple code where I declare a class and a functions inside it. In the main I try to call the function but the call is not made. I don't get any error but if I put a print in order to know if the call has happened nothing…
loar
  • 1,505
  • 1
  • 15
  • 34
-2
votes
1 answer

Where to Use Class Method ,Instance Method in Objective-C

"Instance" mean in Objective-C? Kindly tell me where to use Class Method And where to use Instance Method,also tell me where we use (Instacetype) method? why/where we use multi Parameters?
-2
votes
2 answers

python how to invoke classmethod if I have only it's object

Assuming I have class class Class(object): @register_method_to_later_execution @classmethod def my_class_method(cls): ... and @classmethod object. like this a = Class.my_class_method I need to be able to start executing it only…
Ph0en1x
  • 9,943
  • 8
  • 48
  • 97
-2
votes
4 answers

Class methods in PHP

I am coming from the Ruby world and I have a PHP project I currently work on. Like in Ruby scripts, is it possible to declare class methods in PHP? Basically, I'm asking what the equivalent of the following code would be in PHP class A def hello;…
Igbanam
  • 5,904
  • 5
  • 44
  • 68
-3
votes
1 answer

how to set a variable of a +class method

I am passing a uitextfield string over to a class method (+) with that method I want to instantiate a NSString with the value from the textfield that will be used in another method in the same class. However because this method is (+) I cannot use…
tinhead
  • 385
  • 2
  • 10
  • 29
-3
votes
1 answer

Ruby - defining self method in metaclass of a ruby class

class A @@class_var = "A class variable" def initialize @var = "A instance variable" end def m1 puts @var end def m2 puts @@class_var end end class << A def self.m3 puts "im m3" end end What happen to method m3…
-3
votes
1 answer

Python, Error: "function is not defined" ,

I have 2 @classmethod: one of them is 'operators' and other one is 'pretty_print_2'. in 'operators' i need to call 'pretty_print_2'. The first method is as follow: @classmethod def operators(cls, operator_filter=None, limit_filter=0, ncores=1,…
p.sh
  • 67
  • 1
  • 9
-3
votes
1 answer

Why would I use classmethod constructor in Python?

I am reading Effective Python by Slatkin. In item 24, he talks about achieving polymorphism in python by using classmethod functions that play the role of constructors. However, it is not clear to me why this is necessary. Why can we not achieve the…
Baron Yugovich
  • 3,843
  • 12
  • 48
  • 76
-3
votes
3 answers

How to use functions inside @classmethod decorator

When using @classmethod this is passed first instead of self. Now inside the method with this decorator i need to call functions that are not defined inside this decorator but are defined in the class. How can i call the two functions get_int_input …
Achilles
  • 195
  • 3
  • 12
-4
votes
1 answer

Can equals() and hashCode() be lambdas?

I am new to Java. Can someone explain to me what is the difference between using lambda and method here? Method equals() @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Book)) { …
createdbyjurand
  • 1,177
  • 1
  • 6
  • 6
1 2 3
60
61