Objects with the same attributes and methods belongs to the same class?
-
Can’t I declare two identical classes with the same methods and attributes, instanciate them and have “objects with the same attributes and methods belonging to different classes“?
-
Can’t I declare a class A and a sub-class B (children of the class A) both with the same methods and attributes (and don’t declare any new attribute or method on the class B), instanciate them and have “objects with the same attributes and methods belonging to different classes“?
This question is not about good practices… It’s about the logical value (true or false) of the question on the title.
You don’t specify what language(s) you’re talking about; perhaps there’s some exotic language that has the property you describe, but at least in languages like Java and C++ there’s no concept of inferring that two classes are “the same” based on what methods/instance variables they declare.
So, the answer is “no, they are not the same class, even though they look the same”.
The sub-class case is a little different: if you declare
Bas a subclass ofA(without adding any methods or variables), they are still different classes, but an object of classBalso “is-a”A, because of normal inheritance rules.