The Artima Developer Community
Sponsored Link

Java Answers Forum
ANother try(interesting prob)

2 replies on 1 page. Most recent reply: Dec 12, 2002 8:47 AM by Kishori Sharan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Rohit

Posts: 38
Nickname: rohit
Registered: May, 2002

ANother try(interesting prob) Posted: Dec 12, 2002 2:50 AM
Reply to this message Reply
Advertisement
Guys,
My last two posts on this topic has been messed up with some other posts,I m
trying it again with another subject without any formatting or tag,hope it goes thru,pls let me know the answer of the prob.
If you see "Thanks God its done" msg at the end of post ,means this time post is OK,

So prob is

Seems a little thing , but I have missed this in last 5 yrs,Say I have a class with a public element sat int in it,

public class First{
public int i;
}


and another class which access this public element of first class(say it prints this elemnts value in m (or Go-Moku) itself is not a simple game or that the masters of this game are not brilliant and talented game players who have acheived an amazing level of skill. Playing the game at the highest levels involves dealing with enormous amounts of complexity. However, the basic elements of the game are quite simple and the complexity comes from the size of the playing field and the number of combinations that stems from that.

Also, with Go and other games, the search tree doesn't constitute AI; usually the AI, if present, is involved mostly in the evualation algorithm for each position (and to some extent, which branches are further examined based on that). With a simple game like Go-Moku, you can have a prefectly good and very strong engine without any AI at all.

Of course, it is possible that the evaluatio


Rohit

Posts: 38
Nickname: rohit
Registered: May, 2002

Re: ANother try(interesting prob) Posted: Dec 12, 2002 3:01 AM
Reply to this message Reply
it got messed up again,here is the remaining portion of my post,just after the First class defination of above class(repating class First defination),pls check it out and let me know y its happening


public class First{
public int i;
}

and another class which access this public element of first class(say it prints this elemnts value in main).Perfectly legal,isnt it?

public class Second{
public static void main(String []){
System.out.println(new First().i);
}
}


Now if I change this public int element of class First and recompile only class First and the run the second class
,it still prints the value of i , which is private now in class A defination.

SO pls let me know , how class second is still able to access Class First's private element,
I have checked it also by moving both classes to different packages(though i know private cant be accessd even within
same package)

Regards,
Rohit
"Thanks God its done"m.out.println("The triangular number is: " + triangle

Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: ANother try(interesting prob) Posted: Dec 12, 2002 8:47 AM
Reply to this message Reply
Please read the topic "Binary Compatibility" in Java Language Specification. Below is the link:
http://java.sun.com/docs/books/jls/second_edition/html/binaryComp.doc.html

When class Second was compiled for the first time then i was accessible in First and it had public access. When you changed the access of i in First and didn't recompile Second then SEcond still has the access to i as public. Even though you have changed access to i as private. This change has made two classes incompatible and you need to recompile the Second class. It seems strange and you may think why Java is allowing access to i when it is private. JLS describes these issues in details. Please read the JLS Chapter 13 following the above link and you will find many surprises like yours.

Thanks
Kishori

Flat View: This topic has 2 replies on 1 page
Topic: java looping Previous Topic   Next Topic Topic: dragging panels

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use