Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Groovy is able to call *private* java methods/variables

888616Sep 27 2011 — edited Sep 28 2011
Why are we able to call private java methods or variables from Groovy scripts?

GroovyMainClass.groovy -->
public class GroovyMainClass {

	public static void main(String[] args) {
	
		PrivateMethodClass pc	=	new PrivateMethodClass();
		pc.privateMethod();
		
		println "Private var ->"+pc.pVar;
	}
}
PrivateMethodClass.java -->
public class PrivateMethodClass {
	
	private int pVar	=	1;
	
	private void privateMethod(){
		System.out.println("Private Method Called");
	}
	
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 25 2011
Added on Sep 27 2011
4 comments
1,218 views