Java Fundamental Questions

  1. Which of these are legal identifiers. Select the three correct answers.
    1. number_1
    2. number_a
    3. $1234
    4. -volatile
  2. Which of these are not legal identifiers. Select the four correct answers.
    1. 1alpha
    2. _abcd
    3. xy+abc
    4. transient
    5. account-num
    6. very_long_name
  3. Which of the following are keywords in Java. Select the two correct answers.
    1. friend
    2. NULL
    3. implement
    4. synchronized
    5. throws
  4. Which of the following are Java keywords. Select the four correct answers.
    1. super
    2. strictfp
    3. void
    4. synchronize
    5. instanceof
  5. Which of these are Java keywords. Select the five correct answers
    1. TRUE
    2. volatile
    3. transient
    4. native
    5. interface
    6. then
    7. new
  6. Using up to four characters, write the Java representation of octal literal 6.
  7. Using up to four characters, write the Java representation of integer literal 3 in hexadecimal.
  8. Using up to four characters, write the Java representation of integer literal 10 in hexadecimal.
  9. What is the minimum value of char type. Select the one correct answer.
    1. 0
    2. -215
    3. -28
    4. -215 – 1
    5. -216
    6. -216 – 1
  10. How many bytes are used to represent the primitive data type int in Java. Select the one correct answer.
    1. 2
    2. 4
    3. 8
    4. 1
    5. The number of bytes to represent an int is compiler dependent.
  11. What is the legal range of values for a variable declared as a byte. Select the one correct answer.
    1. 0 to 256
    2. 0 to 255
    3. -128 to 127
    4. -128 to 128
    5. -127 to 128
    6. -215 to 215 – 1
  12. The width in bits of double primitive type in Java is –. Select the one correct answer.
    1. The width of double is platform dependent
    2. 64
    3. 128
    4. 8
    5. 4
  13. What would happen when the following is compiled and executed. Select the one correct answer.

    1. The program compiles and prints y is 0 when executed.
    2. The program compiles and prints y is 1 when executed.
    3. The program compiles and prints y is 2 when executed.
    4. The program does not compile complaining about y not being initialized.
    5. The program throws a runtime exception.
  14. What would happen when the following is compiled and executed. Select the one correct answer.

    1. The program does not compile because x, y and name are not initialized.
    2. The program throws a runtime exception as x, y, and name are used before initialization.
    3. The program prints pnt is 0 0.
    4. The program prints pnt is null 0 0.
    5. The program prints pnt is NULL false false
  15. The initial value of an instance variable of type String that is not explicitly initialized in the program is –. Select the one correct answer.
    1. null
    2. “”
    3. NULL
    4. 0
    5. The instance variable must be explicitly assigned.
  16. The initial value of a local variable of type String that is not explicitly initialized and which is defined in a member function of a class. Select the one correct answer.
    1. null
    2. “”
    3. NULL
    4. 0
    5. The local variable must be explicitly assigned.
  17. Which of the following are legal Java programs. Select the four correct answers.
    1. // The comments come before the package
      package pkg;
      import java.awt.*;
      class C{}
    2. package pkg;
      import java.awt.*;
      class C{}
    3. package pkg1;
      package pkg2;
      import java.awt.*;
      class C{}
    4. package pkg;
      import java.awt.*;
    5. import java.awt.*;
      class C{}
    6. import java.awt.*;
      package pkg;
      class C {}
  18. Which of the following statements are correct. Select the four correct answers.
    1. A Java program must have a package statement.
    2. A package statement if present must be the first statement of the program (barring any comments).
    3. If a Java program defines both a package and import statement, then the import statement must come before the package statement.
    4. An empty file is a valid source file.
    5. A Java file without any class or interface definitions can also be compiled.
    6. If an import statement is present, it must appear before any class or interface definitions.
  19. What would be the results of compiling and running the following class. Select the one correct answer.

    1. The program does not compile as there is no main method defined.
    2. The program compiles and runs generating an output of “test”
    3. The program compiles and runs but does not generate any output.
    4. The program compiles but does not run.
  20. Which of these are valid declarations for the main method? Select the one correct answer.
    1. public void main();
    2. public static void main(String args[]);
    3. static public void main(String);
    4. public static void main(String );
    5. public static int main(String args[]);
  21. Which of the following are valid declarations for the main method. Select the three correct answers.
    1. public static void main(String args[]);
    2. public static void main(String []args);
    3. final static public void main (String args[]);
    4. public static int main(String args[]);
    5. public static abstract void main(String args[]);
  22. What happens when the following program is compiled and executed with the command – java test. Select the one correct answer.

    1. The program compiles and runs but does not print anything.
    2. The program compiles and runs and prints 0
    3. The program compiles and runs and prints 1
    4. The program compiles and runs and prints 2
    5. The program does not compile.
  23. What is the result of compiling and running this program? Select the one correct answer.

     

    1. The program does not compile as k is being read without being initialized.
    2. The program does not compile because of the statement k = j = i = 1;
    3. The program compiles and runs printing 0.
    4. The program compiles and runs printing 1.
    5. The program compiles and runs printing 2.
  24. What gets printed on the standard output when the class below is compiled and executed by entering “java test lets see what happens”. Select the one correct answer.

    1. The program will throw an ArrayIndexOutOfBounds exception.
    2. The program will print “java test”
    3. The program will print “java happens”;
    4. The program will print “test happens”
    5. The program will print “lets happens”
  25. What gets printed on the standard output when the class below is compiled and executed by entering “java test lets see what happens”. Select the one correct answer.

    1. The program will throw an ArrayIndexOutOfBounds exception.
    2. The program will print “java test”
    3. The program will print “java happens”;
    4. The program will print “test happens”
    5. The program will print “lets happens”
  26. What all gets printed on the standard output when the class below is compiled and executed by entering “java test lets see what happens”. Select the two correct answers.

    1. java
    2. test
    3. lets
    4. 3
    5. 4
    6. 5
    7. 6
  27. What happens when the following program is compiled and run. Select the one correct answer.

    1. The program does not compile.
    2. The program prints 0.
    3. The program prints 1.
    4. The program prints 2.
    5. The program prints 4.
  28. What happens when the following program is compiled and run. Select the one correct answer.

    1. The program does not compile.
    2. The program prints 0.
    3. The program prints 1.
    4. The program prints 2.
    5. The program prints 4.
  29. What happens when the following program is compiled and run. Select the one correct answer.

    1. The program does not compile.
    2. The program prints 0.
    3. The program prints 1.
    4. The program prints 2.
    5. The program prints 4.
  30. What happens when the following program is compiled and run. Select the one correct answer.

    1. The program does not compile.
    2. The program prints 0.
    3. The program prints 1.
    4. The program prints 2.
    5. The program prints 4.

Answers to questions on Language Fundamentals

  1. a, b, c
  2. a, c, d, e
  3. d, e
  4. a, b, c, e. Please note that strictfp is a new keyword in Java 2. SeeSun’s site for more details.
  5. b, c, d, e, g
  6. Any of the following are correct answers – 06, 006, or 0006
  7. Any of the following are correct answers – 0x03, 0X03, 0X3 or 0x3
  8. Any of the following are correct answers – 0x0a, 0X0a, 0Xa, 0xa, 0x0A, 0X0A, 0XA, 0xA
  9. a
  10. b
  11. c
  12. b
  13. d. The variable y is getting read before being properly initialized.
  14. d. Instance variable of type int and String are initialized to 0 and null respectively.
  15. a
  16. e
  17. a, b, d, e
  18. b, d, e, f
  19. d
  20. b
  21. a, b, c
  22. a
  23. d
  24. e
  25. a
  26. c, e
  27. e
  28. c
  29. e
  30. c

1. Online Compilers - Compile & Run your C/C++ programs:

✅ Online Compilers

2. Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by Fresh2Refresh.com





Share this website !!!
Facebook Twitter Linkedin

Post Your Thoughts

Close
We Support JALLIKATTU !!!
We Support JALLIKATTU!
By Fresh2Refresh.com
Show Your Support as well. Thanks!