Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with "for each" and "protected"  RSS feed

 
Emilian Chmiel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I wrote 3 projects in 1 package "Points":

1) point1D


2)point2D

3) with main

 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you copy the full text of the compiler's error messages and paste it here?
 
Stephan van Hulst
Saloon Keeper
Posts: 7821
142
  • Likes 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Emilian Chmiel wrote:

data is a point1D[], so obviously you can get point1D objects out of it. You can fill it with point2D objects as well, because point2D extends point1D.

Emilian Chmiel wrote:

Protected access is less restrictive than default access. If your classes are all in the same package, they can access each other's protected members.

Emilian Chmiel wrote:

You can't change the type of variables once they are declared. Casting only allows you to treat a reference to an object as if it's a reference to a more specific type.

A few other remarks:
  • Don't put block statements on one line. Each statement within a block should be on their own line.
  • Package names should start with a lower case letter.
  • Class names should start with a upper case letter.
  • Variable names should start with a lower case letter.
  • You don't have to call super() in constructors, it's implicit.
  • You don't have to initialize non-final numeric fields to 0, it's done automatically.
  • Use the @Override notation when overriding a method.

  • Here's an example:

     
    Emilian Chmiel
    Greenhorn
    Posts: 15
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for tips ...
     
    Ganesh Patekar
    Bartender
    Posts: 696
    23
    Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    So beautifully explained Stephan!
     
    Don't get me started about those stupid light bulbs.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!