Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Understanding few trips/traps of SCJP exam

 
Rahul Choudhary
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everyone. I was going through one of the FAQs in SCJP FAQ Page which was What are some potential trips/traps in the SCJP exam?

Two sentences I did not understand and I was hoping someone could explain them.

1. Forward references to variables gives a compiler error.
2. Primitive array types can never be assigned to each other, even though the primitives themselves can be assigned. For example, ArrayofLongPrimitives = ArrayofIntegerPrimitives gives compiler error even though longvar = intvar is perfectly valid.

Thanks.
 
Abhilash Sharma
Ranch Hand
Posts: 67
Eclipse IDE Fedora Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul Choudhary wrote:Hey everyone. I was going through one of the FAQs in SCJP FAQ Page which was What are some potential trips/traps in the SCJP exam?

Two sentences I did not understand and I was hoping someone could explain them.

1. Forward references to variables gives a compiler error.
2. Primitive array types can never be assigned to each other, even though the primitives themselves can be assigned. For example, ArrayofLongPrimitives = ArrayofIntegerPrimitives gives compiler error even though longvar = intvar is perfectly valid.

Thanks.


1. Forward referencing means that you are trying to use a variable before it's initialization in a class.

}
but in this case


2.Arrays are object in java. So you can assign them to each other if they are of same type.

for example
 
Rahul Choudhary
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for well written examples Abhilash. That helped
 
Danjel Nyberg
Greenhorn
Posts: 15
Eclipse IDE Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say that this line of code would not compile



however if you put it like this, then it would work



Regards
/Danjel
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic