• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

couple of questions

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.)
public class Building {//whatever}
public class House extends Building
{//whatever}
is this legal?
Building b = new House();
is this legal?
House h = new Building();
2.) unary operation is automatically converted to "int" except += or --
so is this legal?
char c = 'a';
c++; //byte or int?
or this?
byte b = 1;
b++; //returns byte or int?
so what's an example of another unary operator that automatically casts char, byte and short to int?
Thanks guys, i know my question is awkwardly stated. I'm just in a rush before I forget.
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(I)
is this legal?
Building b = new House();
yes it is legal both during compile time and run time
(II)
is this legal?
House h = new Building();
this is not legal during compile time as the Building instance needs to be explicitly casted to a House instance.
(III)
so is this legal?
char c = 'a';
c++; //byte or int?
this is legal and will return a char. Th unary operators of ++ and -- implicitly cast the primitive varibale to the varibale type
(IV)
byte b = 1;
b++;
The same reasoning of (III) holds..
Hope this helps
Anand
 
Ranch Hand
Posts: 2378
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lee,
Note that the two classes must be in different source files if you write ---

public class Building {//whatever}
public class House extends Building
{//whatever}

as both the classes are declared public

------------------
azaman
[This message has been edited by Ashik uzzaman (edited July 15, 2001).]
 
Christophe Lee
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Anand,
It did help.
And thanks, ya I do know two public classes should be in different files
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic