Win a copy of Python Continuous Integration and Delivery this week in the Python 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

How to point into an constructor value?  RSS feed

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


How can i access one of my values in the constructor inside the main? this way?


Thank you
 
author & internet detective
Posts: 39148
724
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rianb,
YOu access the instance variables, not the values "inside" the constructor. The constructor is like a method so the variables there are local.

To access an instance variable from the same class, you can write

 
Bartender
Posts: 5636
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is normally done with a getter but because you haven't declared the fields private you can do this.
 
Bartender
Posts: 678
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, note that you should probably not name your class "Integer" since Java has a standard class by that name.
 
There’s no place like 127.0.0.1. But I'll always remember this tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!