0

Introduction to Java

Description: Introduction to Java
Number of Questions: 15
Created by:
Tags: Introduction to Java Java/Oracle /C/C++ Basics of Java Java
Attempted 0/15 Correct 0 Score 0

Java does not support __________.

  1. arrays

  2. multithreading

  3. pointers

  4. constructors


Correct Option: C
Explanation:

Java does not support pointers due to security reasons.

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

  1. java

  2. javac

  3. jvm

  4. jcc


Correct Option: B
Explanation:

We must execute the javac command to compile a java program(.java extension file). The syntax is as follows: javac <filename>

Which of the following is a part of class definition?

  1. Variables

  2. Methods

  3. Constructors

  4. All of the above


Correct Option: D
Explanation:

Instance variables, instance methods and constructors are a part of class definition.

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


Correct Option: C
Explanation:

After compilation of the file Myprog.java, byte code is produced. The file name of this byte code is Myprog.class.

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


Correct Option: A
Explanation:

Byte code is always generated by the Java compiler. This byte code is platform independent.

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.


Correct Option: B
Explanation:

Here, student may be a class or an object but result is the method.

Which operator is used for the bitwise XOR in Java?

  1. ~

  2. &

  3. ^


Correct Option: D
Explanation:

The ^ operator is used for the bitwise XOR in Java.

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

  1. 5

  2. 6

  3. 7

  4. 8


Correct Option: A
Explanation:

The >> is the right shift operator. 23>>2 =10111(binary value of 23) is right shift twice. =101 ( 11 is dropped) =5

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];


Correct Option: A
Explanation:

The declaration Student s[] is incorrect. All the other array declarations are correct.

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


Correct Option: B
Explanation:

The storage capacity of different data types is int - 4 bytes short - 2 bytes byte - 1 byte long - 8 bytes

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


Correct Option: C
Explanation:

The file name should be same as the class name containing the main method with an extension “.java”.

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

  1.   class abc {
       Public static void main(String args[]) {……………}
      }
    
  2.   class abc {
       public Static void main(String args[]) {……………}
      }
    
  3.   class abc {
       Public static void Main(String args[]) {……………}
      }
    
  4.   class abc {
       public static void main(String args[]) {……………}
      }
    

Correct Option: D
Explanation:

The correct format for a Java program is as follows: class abc { public static void main(String args[]) { …………… } } Here, the keywords class, public and static must be in lower case. String is the class name.

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 ;] }


Correct Option: A
Explanation:

The correct syntax is as follows: switch(exp) { case value1: statement_1; case value2: statement_2; …………………… case valuen: statement_n; [default: statements ;] } The default statement is optional.

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

  1. throw

  2. cout

  3. const

  4. cin


Correct Option: C
Explanation:

The final keyword declares the variable as a constant. The final variable has to be initialized only once. The same process is done in C++ by the keyword const.

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.


Correct Option: D
Explanation:

Protected method is accessible from inside the class and all the classes defined in the same package, where the class is defined itself.

- Hide questions