• 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 wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Question

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)Anonymous Inner can implement an interface, extend a nonstatic class(but not at same time).True or false?Why?How to complete?
2)
final int i=2;
byte b=i;
the compile is ok.Why do not need explicit cast?
Thank you!

 
Enthuware Software Support
Posts: 4906
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
True. What do you mean by "how to complete"???
2)
Refer to: http://enthuware.com/jqplus/FAJQuestions.html
HTH,
Paul.
------------------
Get Certified, Guaranteed!
http://pages.about.com/jqplus
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An anonymous inner class either implements an interface OR extends an object. You lost me on the non-static class part. An anonymous class is either static or non-static based on the CONTEXT of the declaration (if in a static method it is a static inner class). The access rules for member and local variables are governed like any other inner class.
To construct an extended object
new TheObject([any existing constructor args]) {};
You can't specify your own constructor, so if you need to set additional member variables you can specify an instance initializer, but not your own constructor.
To construct an interface
new InterfaceName ([no arguments allowed!]) {};
The object extends Object.
Question 2....
An implicit cast is done for you if and only if the right side is a type of INT and it's value is known at compile time (i.e., final) and the value is in range of the left type.
So you have a final int=2 being assigned to a byte. Remove the final and error, change to short and error, change to 128 and error.
 
Paul Anilprem
Enthuware Software Support
Posts: 4906
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Small glitch there, Scott. Implicit narrowing will occur for byte, char, short and int (not just for int).
-Paul.


------------------
Get Certified, Guaranteed!
http://enthuware.com/jqplus
 
scott irwin
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right byte, short and char on the left, and an int on the right for assignment. int to int doesn't need cast.
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It�s a tricky question.
Here Thomas said:
�JLS first edition says that during assignment a narrowing primitive conversion is allowed provided:
  • The expression is a constant expression of type int.

  • The type of the variable is byte, short, or char.

  • The value of the expression (which is known at compile time, because it is a constant expression) is representable in the type of the variable.

  • In JLS second edition, the first condition is amended to read:
    • The expression is a constant expression of type byte, short, char or int.

    • My jdk 1.2.2 apparently follows JLS 1st ed, and other people said that JDK 1.3. votes for JLS 2nd edition.
reply
    Bookmark Topic Watch Topic
  • New Topic