11
Answers

basic java doubt ? access specifier ?

SUNIL GUTTA

SUNIL GUTTA

11y
2.3k
1
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)