1

i am new to object oriented programming. why am i getting this nullpointerexception? a quick answer would help me a lot.

public static void Main(string[] args){
    Avatar person;

person.Speak();
}
public class Avatar{
    public Avatar(){}
    public void Speak(){ 
    Console.WriteLine("Avatar says Hello!")
    }
}
Mark Johnson
  • 127
  • 5

1 Answers1

2

You are receiving the null pointer exception because you did not create a new instance of the Avatar class.

To create a new instance do Avatar person = new Avatar();

Ben
  • 176
  • 1
  • 1
  • 14