pages.....
1   2   3   4   5   6   7   
Is Empty .java file a valid source file?
Question:
Can a .java file contain more than one java classes?
Is String a primitive data type in Java?
Is main a keyword in Java?
Is next a keyword in Java?
Is delete a keyword in Java?
Is exit a keyword in Java?
What happens if you dont initialize an instance variable of any of the primitive types in Java?
What will be the initial value of an object reference which is defined as an instance variable?
MyClass c1, c2, c3;
c1 = new MyClass ();
c3 = new MyClass ();
System.out.println ("1" + 3);
Q: | |
|
A: | Yes, an empty .java file is a perfectly valid source file. |
|
|
Q: | |
|
A: | Yes, a .java file contain more than one java classes, provided at the most one of them is a public class. | |
Q: | |
|
A: | No String is not a primitive data type in Java, even though it is one of the most extensively used object. Strings in Java are instances of String class defined in java.lang package. |
|
Q: | |
|
A: | No, main is not a keyword in Java. |
|
Q: | |
|
A: | No, next is not a keyword. |
|
Q: | |
|
A: | No, delete is not a keyword in Java. Java does not make use of explicit destructors the way C++ does. |
|
Q: | |
|
A: | No. To exit a program explicitly you use exit method in System object. |
|
Q: | ||
A: | The scope of a Java variable is determined by the context in which the variable is declared. Thus a java variable can have one of the three scopes at any given point in time. 1. Instance : - These are typical object level variables, they are initialized to default values at the time of creation of object, and remain accessible as long as the object accessible. 2. Local : - These are the variables that are defined within a method. They remain accessbile only during the course of method excecution. When the method finishes execution, these variables fall out of scope. 3. Static: - These are the class level variables. They are initialized when the class is loaded in JVM for the first time and remain there as long as the class remains loaded. They are not tied to any particular object instance. |
|
Q: | ||
A: | The local variables are not initialized to any default value, neither primitives nor object references. If you try to use these variables without initializing them explicitly, the java compiler will not compile the code. It will complain abt the local varaible not being initilized.. | |
Q: | ||
A: | Yes, the main method can be declared final, in addition to being public static. | |
Q: | What will be the output of the following statement? |
|
A: | It will print 13. | |