Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

java rules roundup game

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just finished the java rules roundup game
But I have some remarks/doubts regarding some of the questions, so maybe somebody can clear this up?

Q: an anonymous inner class cannot have a constructor
A: true
-> doesn't it get a default constructor? Since you are creating an instance of the inner class with the new operator, it must have a constructor of some kind? Ofcourse I understand that you cannot specify a constructor yourself, because what would you name it..

Q: methods which are marked protected, can be called on any subclass of the class in which the method is declared
A: true
-> I believe it can be called IN any subclass, but not ON any instance of the subclass, unless it's in the same package. Is that right?

Q: what happens when u divide an integer by a variable with value 0
A: RuntimeException
-> When it's a floating-point variable, no RuntimeException will be thrown

edit: another one that came to mind
Q: member (instance) variables are allways given a default value
A: true
-> Except for final member variables. They must be explicitly initialized (either in the declaration statement, in an initializer block or in each constructor)
[ September 08, 2004: Message edited by: Jimmy Praet ]
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jimmy Praet:

Q: what happens when u divide an integer by a variable with value 0
A: RuntimeException
-> When it's a floating-point variable, no RuntimeException will be thrown

edit: another one that came to mind
Q: member (instance) variables are allways given a default value
A: true
-> Except for final member variables. They must be explicitly initialized (either in the declaration statement, in an initializer block or in each constructor)

[ September 08, 2004: Message edited by: Jimmy Praet ]



I agree with these two...
In floating point variables there is NAN(Not a Number) returned for the things like divide by zero. So no runtime exception occurs.

But i would like to know the explaination of other questions...
 
Jimmy Praet
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well the first one (about anonymous inner classes not having constructors) is merely a misinterpretation of the question I think. I suppose they mean that you can not define a constructor for an inner class your self.

The second one: I'll give an example



protected members can be accessed in same package and IN subclasses.
The Sub class is in an other package, but it inherits the protected member.
The inherited protected member can be accessed inside the subclass, but it becomes private to any code outside the subclass. (Except for subclasses of this subclass)

If Super, Sub and Test were all in the same package then sub.getSuperValue(); would be legal.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Q: an anonymous inner class cannot have a constructor
A: true
-> doesn't it get a default constructor? Since you are creating an instance of the inner class with the new operator, it must have a constructor of some kind? Ofcourse I understand that you cannot specify a constructor yourself, because what would you name it..


It cannot have a constructor it can only use a construction block using {} only


Q: methods which are marked protected, can be called on any subclass of the class in which the method is declared
A: true
-> I believe it can be called IN any subclass, but not ON any instance of the subclass, unless it's in the same package. Is that right?


protected means it can be accessed from outside the package as well


Q: what happens when u divide an integer by a variable with value 0
A: RuntimeException
-> When it's a floating-point variable, no RuntimeException will be thrown


keyword here is integer not double.. i suppose if the variable was a floating point variable either double or float you would be ok


edit: another one that came to mind
Q: member (instance) variables are allways given a default value
A: true
-> Except for final member variables. They must be explicitly initialized (either in the declaration statement, in an initializer block or in each constructor)


member (instance) i think that all final variables are implicitly static also and therfor not instance / member


im still studying for my exam let me know if i have any of this wrong..
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic