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
-4
votes
1 answer

How do I finish the rest of this program? (Overloaded Methods)

I am trying to use a textbook and the internet to learn coding, but I am having some trouble with these types of codes. I know how to do the first part, but I just can not figure out the other part. HERE IS THE PRACTICE ASSIGNMENT: " You need to…
Garrett7
  • 11
  • 1
-4
votes
3 answers

Java arrays in user defined classes

My code is posted below. I'm generating random numerical grades and assigning them letter grades. Will then create a client class to test the program. My issue is towards the end of the program. I'm getting an error saying illegal start of…
-4
votes
1 answer

Objective C eqivalent Swift code?

This is a class method and I am passing block as one of the argument So basically how pass blocks in swift? + (NSURLSessionDataTask *)getAllSongIfo:(NSDictionary *)userInfo withBlock:(void (^)(NSArray *songInfos, NSError *error))block;
Pradeep CR
  • 53
  • 1
  • 6
-6
votes
2 answers

Class method access by dot operator

This question related to knowing something we don't know. I'm researching with "Why people don't use this"? Is any reason behind this related to specific tech? So read it carefully and give downvote or give correct answer. We can write…
Mani
  • 17,549
  • 13
  • 79
  • 100
1 2 3
60
61