SUNIL GUTTA

SUNIL GUTTA

  • NA
  • 1k
  • 394.3k

basic java doubt ? access specifier ?

Oct 26 2013 7:04 PM
Hi

HERE is mu program .. it works fine no problem with that .. but it only compiles when i remove public specifier from the class " Horsetest" .. why is this happening ?? any ideas .. in c# if we declare like this program will execute no compile error .. why 

Program : 
public class HorseTest
{
public static void main (String [] args)
{
  class Horse
 {
 public String name;
 public Horse(String s)
 {
  name = s;
 }
 }
  Object obj = new Horse("Zippo");
 Horse h = (Horse) obj;
 System.out.println(h.name);
 }


please help me :) cheers 

Answers (11)