Introduction to Java

Basic Java programming concepts covering compilation, syntax, operators, arrays, classes, and access modifiers

15 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Java does not support __________.

  1. arrays
  2. multithreading
  3. pointers
  4. constructors
Question 2 Multiple Choice (Single Answer)

Which of the following commands is used to compile a java program(.java extension file)?

  1. java
  2. javac
  3. jvm
  4. jcc
Question 3 Multiple Choice (Single Answer)

Which of the following is a part of class definition?

  1. Variables
  2. Methods
  3. Constructors
  4. All of the above
Question 4 Multiple Choice (Single Answer)

After compilation of file Myprog.java, a new file is created with the name ___________.

  1. Myprog.obj
  2. Myprog.cls
  3. Myprog.class
  4. Myprog.exe
Question 5 Multiple Choice (Single Answer)

Which of the following statements is correct with respect to byte code?
A. Byte code is generated by Java compiler.
B. Byte code is generated by Java virtual machine.

  1. Only A
  2. Only B
  3. Both A and B
  4. Neither A nor B
Question 6 Multiple Choice (Single Answer)

Which of the following is true regarding the following statement in Java?
student.result(marks);

  1. student is the name of a structure.
  2. result is the name of a method.
  3. result is a form of a datatype.
  4. student is the name of a method.
Question 7 Multiple Choice (Single Answer)

Which operator is used for the bitwise XOR in Java?

  1. ~
  2. &
  3. |
  4. ^
Question 8 Multiple Choice (Single Answer)

What is the value of the statement 23>>2 in Java?

  1. 5
  2. 6
  3. 7
  4. 8
Question 9 Multiple Choice (Single Answer)

Which of the following array declarations is not correct?

  1. Student s[];
  2. Student s[]=new Student[4];
  3. Student s[][]=new Student[5][];
  4. Student s[][]=new Student[5][3];
Question 10 Multiple Choice (Single Answer)

Match the following:

1. int A. 2 bytes
2. short B. 1 byte
3. long C. 4 bytes
4. byte D. 8 bytes
  1. 1 - C, 2 - A, 3 - B, 4 - D
  2. 1 - C, 2 - A, 3 - D, 4 - B
  3. 1 - A, 2 - C, 3 - D, 4 - B
  4. 1 - C, 2 - D, 3 - A, 4 - B
Question 11 Multiple Choice (Single Answer)

What will be the file name for the following program?
class Student
{
public static void main(String args[])
{
System.out.println(“Hello Student”);
}
}

  1. Any file name
  2. Student.class
  3. Student.java
  4. Student
Question 12 Multiple Choice (Single Answer)

Which of the following is the correct format of a Java program?

  1. java class abc { Public static void main(String args[]) {……………} }
  2. java class abc { public Static void main(String args[]) {……………} }
  3. java class abc { Public static void Main(String args[]) {……………} }
  4. java class abc { public static void main(String args[]) {……………} }
Question 13 Multiple Choice (Single Answer)

Which of the following is the correct syntax of switch statement in Java?

  1. switch(exp)
    {
    case value1: statement_1;
    case value2: statement_2;
    ……………………
    case valuen: statement_n;
    [default: statements ;]
    }
  2. switch(exp)
    {
    case value1: statement_1;
    case value2: statement_2;
    ……………………
    case valuen: statement_n;
    default: statements ;
    }
  3. switch(exp)
    {
    case value1: statement_1;
    case value2: statement_2;
    ……………………
    case valuen: statement_n;
    }
  4. switch(exp)
    {
    case value1; statement_1;
    case value2; statement_2;
    ……………………
    case valuen; statement_n;
    [default: statements ;]
    }
Question 14 Multiple Choice (Single Answer)

In Java, final keyword gives the same result as ________ declaration in C++.

  1. throw
  2. cout
  3. const
  4. cin
Question 15 Multiple Choice (Single Answer)

If there is a protected method within the Public class, then which of the following statements is correct?

  1. Protected method does not access the public method.
  2. Method is accessible from inside a class and a subclasses.
  3. Protected method is not allowed within the Public class.
  4. Method is accessible from inside the class and all the classes defined in the same package, where the class is defined itself.