I faced a telephonic interview yesterday and it was a most bad - TopicsExpress



          

I faced a telephonic interview yesterday and it was a most bad experience i ever have in my life some of the questions with possible answers discussed here 1.What is the difference between variable declaration and variable definition in java? ans:- The conceptual difference is simple: Declaration: You are declaring that something exists, such as a class, function or variable. You dont say anything about what that class or function looks like, you just say that it exists. Definition: You define how something is implemented, such as a class, function or variable, i.e. you say what it actually is. In Java, there is little difference between the two, and formally speaking, a declaration includes not only the identifier, but also its definition. Here is how I personally interpret the terms in detail: Classes: Java doesnt really separate declarations and definitions as C/C++ does (in header and cpp files). You define them at the point where you declare them. Functions: When youre writing an interface (or an abstract class), you could say that youre declaring a function, without defining it. Ordinary functions however, are always defined right where they are declared. See the body of the function as its definition if you like. Variables: A variable declaration could look like this: int x; (youre declaring that a variable x exists and has type int) either if its a local variable or member field. In Java, theres no information left about x to define, except possible what values it shall hold, which is determined by the assignments to it. Heres a rough summary of how I use the terms: abstract class SomeClass { // class decl. // \ int x; // variable decl. and def. | // | public abstract void someMethod(); // function decl. | // | public int someOtherMethod() { // function decl. | // | class if (Math.random() > .5) // \ | def. return x; // | function definition | else // | | return -x; // / | // | } // | } // /
Posted on: Thu, 27 Mar 2014 03:02:44 +0000

Trending Topics



Recently Viewed Topics




© 2015