set theory subsets and inheirtance in Java I started reading Concepts of Modern Mathematics and naturally, I came across set theory. I was wondering if someone could clarify my understanding for subsets by way of inheritance in Java or any other language.
If I say that $\mathbb K \subset \mathbb R$ and $\mathbb K$ is some set  then would that be the same thing as saying that class A extends B within the context of Java code?  Or in other words, $\mathbb K$ inherits the properties of $\mathbb R$ and furthermore, becomes the "child" of $\mathbb R$ or the $\subset$ (subset) of $\mathbb R$?
Would I be correct in my analogy?
Thanks
 A: The inheritance hierarchy is a bad model for sets and subsets. The main problem is that subsets deal only with single relation, which is containment $\subset$, where inheritance has a two roles:


*

*subtyping polymorphism,

*modeling abilities of objects.


Consider the infamous example of squares and rectangles. In math, of course, the set of all squares is a subset of all rectangles. This may lead to an impression that square should be a subclass of the rectangle (as, the most general Object class it at the very top of the hierarchy). However, this is wrong, because square does not have all the abilities that rectangle has (e.g. having sides of different lengths). However, the other direction, that is the rectangle is a subclass of the square, also has drawbacks, e.g. one could imagine such code
double squareArea(Square s) {
  return s.side*s.side;
}

which is clearly wrong if the square is a superclass of the rectangle. Some think that this code is wrong, other that it makes the OP paradigm broken, and those forced to use OP frequently use the ad-hoc solution (naturally, there are exceptions) being that the abilities-modeling is more important (to the point that the author of the original Java class hierarchy admits he did it wrong, unfortunately I could not find the citation, so take it with a pinch of salt). One way or another (I don't want to start another Xmas vs. Easter discussion), inheritance is a not a good example of sets and subsets. 
If you have to go with Java, there is an interface java.util.Set which would be more helpful that inheritance hierarchy. Indeed, $A \subset B$ if and only if for all $x \in A$ we have $x \in B$, or in java terms
boolean subset(Collection<?> a, Collection<?> b) {
  for (Object elem : b)
    if (!a.contains(b)) 
      return false;
  return true;
}

Just try of interpreting what are you reading in terms of collections, as those were designed to model sets, multisets, sequences, and so on.
I hope I didn't confuse you ;-)
A: Yes, you can represent these subset relations also as type relations in computer languages. However, Java is not exactly a role model for this. Better look at functional languages, like e.g. Lisp or Scheme, where this exactly modelled as so-called "numerical tower" (see e.g. https://en.wikipedia.org/wiki/Numerical_tower). 
In Scheme or Common Lisp you have e.g. that an integer is a rational is a real, modelling exactly this $\mathbb Z\subset \mathbb Q\subset \mathbb R$ subset relation (see e.g. http://en.wikibooks.org/wiki/Common_Lisp/Advanced_topics/Numbers_. 
A: I see where you are coming from in the sense that a subset may often have extra attributes (or constraints on existing attributes) that all the members of its superset may not have. The Liskov substitution principle will not necessarily be violated by a subset subclass. And Java sub-classes allow this although it was not for making subsets that sub-classes were devised.
Other languages like Ada allow sub-typing whereby a subtype is a subset of the set of objects from which the parent type is defined. For example,
-- long_long_integer type is predefined

subtype prime is long_long_integer range 2 .. long_long_integer'last; 

subtype index is long_long_integer range 1 .. long_long_integer'last;   

type primes is array(index range <>) of prime;

But what you seem to want to do is to model set operations within Java and there are no predefined methods in the Java Set interface to do union/intersection/difference/etc. Coders just have to adapt existing Collection methods like add, return, etc to perform basic set operations. Likewise with creating subsets and making supersets.
In a way this is odd. Java usually provides more than enough methods for commonly used operations. Sets are endemic to database processes. And Java is the property of a major database system provider. The coding of these basic operations is fairly trivial. And other set operations may often be very dependent on the nature of the data and how exactly the coder wants to process it. It might be an idea for some later version of Java.
