• 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

Problem with "for each" and "protected"

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I wrote 3 projects in 1 package "Points":

1) point1D


2)point2D

3) with main

 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you copy the full text of the compiler's error messages and paste it here?
 
Saloon Keeper
Posts: 15510
363
  • Likes 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 23
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks for tips ...
     
    Bartender
    Posts: 1251
    87
    Hibernate jQuery Spring MySQL Database Tomcat Server Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    So beautifully explained Stephan!
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic