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
-1
votes
2 answers

Change value of a variable in a different class, without rewriting method

I have two classes. In one class, I have lots of methods that run based one on variable. And in a second class, I want to define a second variable, where the methods of class one run, when this variable is true. However, I'm not sure how to write…
Reena Verma
  • 1,617
  • 2
  • 20
  • 47
-1
votes
2 answers

'is not a function' on calling an method within the same constructor function (JS)

I wanted to call a method within a method of the same class. function Dialog() { this.close = function() { //code }; this.dialog = document.createElement("div"); this.dialog.onclick = function() { …
p98
  • 15
  • 1
  • 4
-1
votes
3 answers

NameError: name 'WIDTH_DEGREES' is not defined

I'm trying to do this MOOC And on this class I wrote exactly the same code but it doesn't work the same for me. I don't understand. My full code is on github. class Zone: ZONE = [] MIN_LONGITUDE_DEGREES = -180 MAX_LONGITUDE_DEGREES =…
user9710018
-1
votes
1 answer

python: make a class object iterable

Here is what i am trying to do: i created a classmethod that returns either an object of dict if not params are added to this method or an object made of list of dicts if any params are added, as code below: @classmethod def make_attr(cls,…
EUPHORAY
  • 453
  • 6
  • 15
-1
votes
1 answer

Property not found on object of type error

I am trying to access a class method from another class but I am getting error. I have a class 'Constants' in which I have written a class method 'changeDateFormat' and accessing it from some viewController. Here is my code. Constants.h @interface…
Palash Bairagi
  • 71
  • 1
  • 1
  • 8
-1
votes
3 answers

Not getting desired output from PHP class

This is my very first question actually. I am under a learning process of OOP PHP and trying to design my first class for Category. Here is my code
Neil
  • 21
  • 4
-1
votes
1 answer

Issues of choosing classmethod over inheritance in Python

What are the main issues I can come across if I choose to use classmethod over Inheritance in Python? A (silly) example would be: class Pizza(object): def __init__(self, ingredients): self.ingredients = ingredients self.cooked =…
-1
votes
1 answer

ruby class method unable to push additional user input to array

It stores the first employee, but when I try to add another employee I am unable to view the additional employees entered. Below is the method for viewing employee record. Thanks for any help! Employee Class class Employee attr_accessor :employee,…
-1
votes
1 answer

Python How to declare a class inside a method when it is required to be global

I have the following function: def create_figures(): circle = figure() square = figure() Then I have the following program: create_figures() circle.get_area() The get_area() method is an error because circle doesn't exist in that scope, so…
Luis
  • 127
  • 1
  • 11
-1
votes
1 answer

Use an array from main in a timer method

I'm working in a Console Application and I want to output the value of an array that exist in the main method inside a timer method. I however have no idea how to send the array values to the timer method as the constructor only takes 4 arguments. …
Jockiie
  • 19
-1
votes
3 answers

How to setup an object before calling class methods like in Java/Spring?

I have an object that needs to be initialised by reading a config file and environment variables. It has class methods, I want to make sure the object is initialised before the classmethod is executed. Is there any way to initialise all classes of…
tt_Gantz
  • 2,786
  • 3
  • 23
  • 43
-1
votes
1 answer

Junit test case for the below method

I am still new to JUnit testing. I am writing junit tests for this method: public void LoadApplet(JPanel panel) { AppletClass applet = new AppletClass(); applet.init(); panel.add(applet,BorderLayout.CENTER); applet.start(); }
Zeeshaan
  • 9
  • 3
-1
votes
1 answer

Retrieving information out of a Class module collection in VB.Net

Currently I'm having an issue/Struggling to understand how to pull the information out of a Class Module. How I understand it is if a Class Module was an Excel sheet an instance would be a row and the public property would be the columns I have…
Alex Gale
  • 55
  • 1
  • 7
-1
votes
1 answer

Why do templates allow for method types of unfinished classes?

Why do templates let you get around incomplete types? I was following an example in a textbook on Nodes, Linked lists and Iterators. I noticed he used a pointer to instances of Lists and Nodes in the Iterator class, but then he also created a…
Congomon
  • 13
  • 3
-1
votes
1 answer

Doesn't work to call instance method from class method

I'm trying to call an instance method from a class method in Swift, but I keep getting the error "Missing argument for parameter #1 in call" on the "someMethod()" call. Do you know why? Here's the code: class ViewController: UIViewController { …
Pætur Magnussen
  • 901
  • 1
  • 11
  • 24