Answer to Question #275942 in Java | JSP | JSF for oboti

Question #275942

Give an example of a class and an example of an object. Describe what a class is, what an object is, and how they are related. Use your examples to illustrate the descriptions.

Your Discussion should be at least 250 words in length, but not more than 750 words. 


1
Expert's answer
2021-12-06T02:16:47-0500

Well, it depends on the language you are using; in pure object-oriented languages ​​where everything is an object (like Smalltalk), classes are no exception and are also objects. In other languages, where classes are not considered first-class citizens, they are simply special language constructs or primitive types. From now on, I will use Smalltalk as the target language due to its support for reflection and consistent styling.


How are class methods only accessible by the name class.method? (internal working). Is this the same as object.method?


Since classes are objects, they in turn are instances of a class (metaclass). Thus, sending a message to a class is simply sending a message to an object whose role is to represent the behavior of the classes. There is a lot of literature, you can take a look, for example, here and here for acquaintance.


And if the class is the same as the object (belongs to the class of the object, which is the superclass of every thing in OO) and we instantiate it (make it an object), can we instantiate a class other than the class object.


I'm not sure if I'm following you here, but just to clarify that Object is not always the superclass of all classes. The point is, if you start tracking the relationship between classes and metaclasses, you might end up with a kind of infinite loop. This is handled differently in different languages, and, for example, in VisualWorks Smalltalk Object is a subclass of nil. The point is, nil is also an object (remember that everything is an object) and doesn't really represent anything. As you might expect, nil is an instance of the class (UndefinedObject) and also implements some of the class's protocols. As a result, it can be used to represent a class form in which nothing inherits :).


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS