I have a syntax question.
I know that object of a class can be created as:
MyClass classname = new MyClass();
but can is it ok if a do the following:
MyClass classname;
//.....some lines of code
classname = new MyClass();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes you can instantiate the object on a different line than the type declaration, however it is only useful when you want to instantiate the object in a different scope: