I faced a rather simple question in an interview.
Why do we use the class keyword for declaring classes?
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.
Short answer: because that’s the way it’s done in C++. Java has taken the bulk of its syntax from C++ – a wise decision, in my opinion, as it really helped with drawing programmers when it was still new.
Now, if your question is why a keyword is needed at all – i.e. why can’t the compiler just deduce where classes are declared – maybe it can, but using a keyword has the benefits of
EDIT: one other things – some things simply cannot be deduced by the compiler in the Java syntax – for example, the only difference between an empty class and an empty interface (both legal in Java) is the
class/interfacekeyword.