This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"is a" and "has a"

 
Judy YU
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I understand, if class A extends class B, we can say that class A is a B, and if in the definition of class A, there is object C (such as Interface , class objects) as class or instance member, we can say A has C. Then, how about class A implements interface E, do we say A is a E? I saw in some mock exam, it is declared as A is-like-a E, but it is not an official term in Java. Can anyone help?
Question 2: is the declaration " all integer types are signed numbers " true or false? As I know, it is true because all integer types(short, byte, int, long) are signed numbers. If "integral type" is used here instead of "integer type", then it will be wrong since integral type includes char as well. Agree?

 
Val Dra
Ranch Hand
Posts: 439
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 2: is the declaration " all integer types are signed numbers " true or false? As I know, it is true because all integer types(short, byte, int, long) are signed numbers. If "integral type" is used here instead of "integer type", then it will be wrong since integral type includes char as well. Agree?
No not all integer values are signed , char is unsigned only positive values 0 - 65000 i believe. Although it's still a numeric type.
 
Gaurav Mantro
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for Question 1.
My understanding is that implements also represents "is a" relationship. "Implements" is implementation of Inheritance only. The diference in implements and extends is that in implement we do not inherit the implementation but just the method signatures and in extends we inherit the implementation also. So from OO prospective they both should be Java's implementation of OO principle of Inheritance and hence the relationship "is a".
 
Judy YU
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your kind reply.
As for question 2: in KR book , page 29, Khalid Mughal provides a chart which separated integer type from character type, although integral type includes both char and integer type. Did Mughal write it wrong? I am really confused.
Judy
 
Sujit Kurtadikar
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A extends B implemnts C
{
Emp e;
}
This can be interpreted as,
class A "is a" class B
class A "behaves like" class C
class A "has a" class Emp
I don't know whether "behaves like" term is used by Java or not,
but it is correct interpretation.
Also we can say, Class A "is like a" Class C
 
Sridhar Katakam
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Four Signed integral types: byte, short, int, long
Unsigned integral type: char
Primitive type 'boolean' is unsigned but it doesn't come under 'integral' types.
I am 100 % sure about the above.
Now coming to integer types, I believe what Judy quoted is true that integer types cover byte, short, int and long which are signed. But ValDra wrote indicating that 'char' is a integer type. How is that possible ?
~Sri~

Originally posted by Val Dra:
Question 2: is the declaration " all integer types are signed numbers " true or false? As I know, it is true because all integer types(short, byte, int, long) are signed numbers. If "integral type" is used here instead of "integer type", then it will be wrong since integral type includes char as well. Agree?
No not all integer values are signed , char is unsigned only positive values 0 - 65000 i believe. Although it's still a numeric type.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic