Java Language | 30 Minute‐Test 3


Instruction

  • Total number of questions : 30.
  • Time alloted : 30 minutes.
  • Each question carry 1 mark.
  • No Negative marks
  • DO NOT refresh the page.
  • All the best :-).

1.

Which data type value is returned by all transcendental math functions?

A.
int
B.
float
C.
double
D.
long

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

2.

What is the output of this program?

    class array_output {

        public static void main(String args[])

        {

                char array_variable [] = new char[10];

      for (int i = 0; i < 10; ++i) {

                array_variable[i] = 'i';

                System.out.print(array_variable[i] + "" );

                i++;

            } 

       }

    }

A.
i i i i i
B.
0 1 2 3 4
C.
i j k l m
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

3.

What is the output of this program?

    class evaluate {

       public static void main(String args[])

        {

            int a[] = {1,2,3,4,5};

            int d[] = a;

            int sum = 0;

            for (int j = 0; j < 3; ++j)

                sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]);

            System.out.println(sum);

        }

    }

A.
38
B.
39
C.
40
D.
41

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None

4.

What is the output of this program?

    class char_increment {

        public static void main(String args[])

        {

            char c1 = 'D';

            char c2 = 84;

            c2++;

            c1++;

            System.out.println(c1 + " "  + c2);

        }

    }

A.
E U
B.
U E
C.
V E
D.
U F

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Operator ++ increments the value of character by 1. c1 and c2 are given values D and 84, when we use ++ operator their values increments by 1, c1 and c2 becomes E and U respectively.

5.

What is the output of this program?

    class array_output {

        public static void main(String args[])

        {

            int array_variable [] = new int[10];

      for (int i = 0; i < 10; ++i) {

                array_variable[i] = i;

                System.out.print(array_variable[i] + " ");

                i++;

            }

        }

    }

A.
0 2 4 6 8
B.
1 3 5 7 9
C.
0 1 2 3 4 5 6 7 8 9
D.
1 2 3 4 5 6 7 8 9 10

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

When an array is declared using new operator then all of its elements are initialized to 0 automatically. for loop body is executed 5 times as whenever controls comes in the loop i value is incremented twice, first by i++ in body of loop then by ++i in increment condition of for loop.

6.

What is the output of this program?

    class increment {

        public static void main(String args[])

        {

            double var1 = 1 + 5;

            double var2 = var1 / 4;

            int var3 = 1 + 5;

            int var4 = var3 / 4;

            System.out.print(var2 + " " + var4);

         }

    }

A.
1 1
B.
0 1
C.
1.5 1
D.
1.5 1.0

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None

7.

What is the output of this program?

    class bitwise_operator {

        public static void main(String args[])

        {

            int var1 = 42;

            int var2 = ~var1;

            System.out.print(var1 + " " + var2);

               }

    }

A.
42 42
B.
43 43
C.
42 -43
D.
42 43

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Unary not operator, ~, inverts all of the bits of its operand. 42 in binary is 00101010 in using ~ operator on var1 and assigning it to var2 we get inverted value of 42 i:e 11010101 which is -43 in decimal.

8.

What is the output of this program?

    class Relational_operator {

        public static void main(String args[])

        {

            int var1 = 5;

            int var2 = 6;

            System.out.print(var1 > var2);

        }

    }

A.
1
B.
0
C.
true
D.
false

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Operator > returns a boolean value. 5 is not greater than 6 therefore false is returned.

9.

What is the output of this program?

    class operators {

        public static void main(String args[])

        {

            int var1 = 5;

            int var2 = 6;

            int var3;

            var3 = ++ var2 * var1 / var2 + var2;

            System.out.print(var3);

        }

    }

A.
10
B.
11
C.
12
D.
56

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Operator ++ has the highest precedence than / , * and +. var2 is incremented to 7 and then used in expression, var3 = 7 * 5 / 7 + 7, gives 12.

10.

What is the output of this program?

    class selection_statements {

        public static void main(String args[])

        {

            int var1 = 5;

            int var2 = 6;

            if ((var2 = 1) == var1)

                System.out.print(var2);

            else

                System.out.print(++var2);

        }

    }

A.
1
B.
2
C.
3
D.
4

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

var2 is initialised to 1. The conditional statement returns false and the else part gets executed.

11.

What is the output of this program?

    class main_class {

        public static void main(String args[])

        {

            int x = 9;

            if (x == 9) {

                int x = 8;

                System.out.println(x);

            }

        }

    }

A.
9
B.
8
C.
Compilation error
D.
Runtime error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Two variables with the same name can’t be created in a class.

12.

What is the output of this program?

    class box {

        int width;

        int height;

        int length;

        int volume;

        void volume(int height, int length, int width) {

             volume = width*height*length;

        }

    }

        class Prameterized_method{

        public static void main(String args[])

        {

            box obj = new box();

            obj.height = 1;

            obj.length = 5;

            obj.width = 5;

            obj.volume(3,2,1);

            System.out.println(obj.volume);

                }

    }

A.
0
B.
1
C.
6
D.
25

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

13.

What is the output of this program?

    class box {

        int width;

        int height;

        int length;

        int volume;

        box() {

            width = 5;

            height = 5;

            length = 6;

        }

        void volume() {

             volume = width*height*length;

        }

    }

        class constructor_output { 

       public static void main(String args[])

        {

            box obj = new box();

            obj.volume();

            System.out.println(obj.volume);

        }

   }

A.
100
B.
150
C.
200
D.
250

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

14.

What is the output of this program?

    class overload

{

        int x; int y;

        void add(int a) {

            x =  a + 1;

        }        void add(int a, int b){

            x =  a + 2;

        }

            }

        class Overload_methods { 

       public static void main(String args[])  

      {      

      overload obj = new overload();  

            int a = 0;  

          obj.add(6);     

       System.out.println(obj.x);  

           } 

 }

A.
5
B.
6
C.
7
D.
8

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

15.

What is the output of this program?

    class access{

        public int x; private int y;

        void cal(int a, int b){

            x =  a + 1;

            y =  b;

        }

            }

        class access_specifier {

        public static void main(String args[])

        {

            access obj = new access();

               obj.cal(2, 3);

            System.out.println(obj.x + " " + obj.y);

             }

   }

A.
3 3
B.
2 3
C.
Runtime Error
D.
Compilation Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

16.

Which of these methods must be made static?

A.
main()
B.
delete()
C.
run()
D.
finalize()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

main() method must be declared static, main() method is called by Java’s run time system before any object of any class exists.

17.

What is the output of this program?

    class string_demo

{

        public static void main(String args[]) 

       {

            String obj = "I" + "like" + "Java";

               System.out.println(obj);

             }

   }

A.
I
B.
like
C.
Java
D.
IlikeJava

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Java defines an operator +, it is used to concatenate strings.

18.

What is the output of this program?

    class A {

        int i;

        void display() {

            System.out.println(i);

        }

    }

        class B extends A {

        int j;

        void display() {

            System.out.println(j);

        }

    }

        class inheritance_demo {

        public static void main(String args[])

        {

            B obj = new B();

            obj.i=1;

            obj.j=2;

               obj.display();

             } 

 }

A.
0
B.
1
C.
2
D.
Compilation Error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

class A & class B both contain display() method, class B inherits class A, when display() method is called by object of class B, display() method of class B is executed rather than that of Class A.

19.

Which of these is supported by method overriding in Java?

A.
Abstraction
B.
Encapsulation
C.
Polymorphism
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

20.

Which of these class relies upon its subclasses for complete implementation of its methods?

A.
Object class
B.
abstract class
C.
ArrayList class
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

21.

Which of these is an oncorrect statement?

A.
String objects are immutable, they cannot be changed
B.
String object can point to some other reference of String variable.
C.
StringBuffer class is used to store string in a buffer for later use.
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

StringBuffer class is used to create strings that can be modified after they are created.

22.

What is the output of this program?

    class output {

        public static void main(String args[])

        {

           String c = "Hello i love java";

           int start = 2;

           int end = 9;

           char s[]=new char[end-start];

           c.getChars(start,end,s,0);

           System.out.println(s);

        }

    }

A.
Hello, i love java
B.
i love ja
C.
lo i lo
D.
llo i l

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

getChars(start,end,s,0) returns an array from the string c, starting index of array is pointed by start and ending index is pointed by end. s is the target character array where the new string of letters is going to be stored and the new string will be stored from 0th position in s.

23.

What is the output of this program?

    class output {

        public static void main(String args[])

        {

           String c = "  Hello World  ";

           String s = c.trim();

           System.out.println("\""+s+"\"");

        }

    }

A.
“”Hello World””
B.
“”Hello World”
C.
“Hello World”
D.
Hello world

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

trim() method is used to remove leading and trailing whitespaces in a string.

24.

What is the output of this program?

    class output {

        public static void main(String args[])

        {

            String a = "hello i love java";

            System.out.println(a.indexOf('e')+" "+a.indexOf('a')+" "+a.lastIndexOf('l')+" "+a.lastIndexOf('v'));

        }

    }

A.
6 4 6 9
B.
5 4 5 9
C.
7 8 8 9
D.
1 14 8 15

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

indexof(‘c’) and lastIndexof(‘c’) are pre defined function which are used to get the index of first and last occurrence of the character pointed by c in the given array.

25.

What is the output of this program?

    class output {

        public static void main(String args[])

        {

             StringBuffer c = new StringBuffer("Hello");

             System.out.println(c.length());

        }

    }

A.
4
B.
5
C.
6
D.
7

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

length() method is used to obtain length of StringBuffer object, length of “Hello” is 5.

26.

What is the output of this program?

    class output {

        public static void main(String args[])

        {

           String c = "Hello i love java";

           boolean var;

           var = c.startsWith("hello");

           System.out.println(var);

        }

    }

A.
true
B.
false
C.
0
D.
1

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

startsWith() method is case sensitive “hello” and “Hello” are treated differently, hence false is stored in var.

27.

Which of the following is incorrect statement about packages?

A.
Package defines a namespace in which classes are stored.
B.
A package can contain other package within it.
C.
Java uses file system directories to store packages.
D.
A package can be renamed without renaming the directory in which the classes are stored.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

A package can be renamed only after renaming the directory in which the classes are stored.

28.

Which of the following is incorrect statement about packages?

A.
Interfaces specifies what class must do but not how it does.
B.
Interfaces are specified public if they are to be accessed by any code in the program.
C.
All variables in interface are implicitly final and static.
D.
All variables are static and methods are public if interface is defined pubic.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

All methods and variables are implicitly public if interface is declared public.

29.

Which of these methods is used to check for infinitely large and small values?

A.
isInfinite()
B.
isNaN()
C.
Isinfinite()
D.
IsNaN()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

isinfinite() method returns true is the value being tested is infinitely large or small in magnitude.

30.

Which of these methods is used to obtain value of invoking object as a long?

A.
long value()
B.
long longValue()
C.
Long longvalue()
D.
Long Longvalue()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

long longValue() is used to obtain value of invoking object as a long.

Submit your test now to view the Results and Statistics with answer explanation.