Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

core java , access variable without encapsulation.  RSS feed

 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my test1.java




This is test.java





I want know that how to access variable from another java class without encapsulation, I made these different classes, but this not works , can anyone help me how to do this?
 
Paweł Baczyński
Bartender
Posts: 2054
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this: ItDoesntWorkIsUseless (it is a link).

Your class test1 does not compile because it is illegal to put arbitrary statements into class body.

You can set the value of a while declaring it:or in a constructor:or in an initialization block (rarely useful):
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sarojni agrwal wrote:I want know that how to access variable from another java class without encapsulation...

Why do you want to do that? Encapsulation is there to help you; it's not something bad.

Winston
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!