Java Programming

A Test to check the Programming Concepts in Java

25 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

If m = -16 and n = -5 (m and n are int types), the result of the expression m%n is

  1. -1
  2. 1
  3. -3
  4. 3
Question 2 Multiple Choice (Single Answer)

Which of the following is not supported by Java?

  1. Polymorphism
  2. Inheritance
  3. Message communication
  4. Operator overloading
Question 3 Multiple Choice (Single Answer)

Consider the following code:
If(num<=0) If(num<0) System.out.println(“Number is negative”) Else System.out.ptintln(“Number is positive”); If num=0, then output will become

  1. 0
  2. negative
  3. positive
  4. none of these
Question 4 Multiple Choice (Single Answer)

A variable declared inside the for loop control cannot be referenced outside the loop

  1. true
  2. false
Question 5 Multiple Choice (Single Answer)

How can the under given statement be written?If (p<100) Flag = 10; Else Flag = 20;

  1. flag=(p<100) ? 10 : 20;
  2. flag=(p<100) : 10 ? 20 ;
  3. flag=(p<100) : 20 ? 10 ;
  4. flag=(p<100) ? 20 : 10;
Question 6 Multiple Choice (Single Answer)

Objects cannot be passed to a method by use of call-by reference

  1. true
  2. false
Question 7 Multiple Choice (Single Answer)

Every try statement should be followed by at least one catch statement

  1. true
  2. false
Question 8 Multiple Choice (Single Answer)

_________ must be the first statement of Java source file (except comment statements).

  1. Class
  2. Package
  3. Interface
  4. Main method
Question 9 Multiple Choice (Single Answer)

The method s1.compareTo(s2) returns

  1. True if s1 < s2
  2. Negative if s1<s2, positive if s1>s2 and zero if s1=s2
  3. Zero if s1=s2
  4. Positive if s1 > s2
Question 10 Multiple Choice (Single Answer)

What is wrong with the following code?
Switch(x) {Case 1: num1 = 100; num2 = 200; Case 2: num3 = 300: Break; num4 = 400;}

  1. Nothing is wrong
  2. Break is not used in case 2
  3. Default is not there
  4. Num4 = 400 is not reachable
Question 11 Multiple Choice (Single Answer)

What is AWT?

  1. Abstract Window Toolkit
  2. Active Window Terminal
  3. Abstract Window Terminal
  4. Active Window Toolkit
Question 12 Multiple Choice (Single Answer)

Which one of the following is not in Java.lang package?

  1. Arithmetic Exception
  2. Array Store Exception
  3. Float
  4. Math
Question 13 Multiple Choice (Single Answer)

When we implement interface method it should be declared as public.

  1. true
  2. false
Question 14 Multiple Choice (Single Answer)

Any method in a superclass can be overridden in its subclass.

  1. true
  2. false
Question 15 Multiple Choice (Single Answer)

Give the output of the following: int n=10; while (true) {if (n<5) continue; n=n-2;} System.out.println(n);

  1. 5
  2. 10
  3. 2
  4. Infinite loop
Question 16 Multiple Choice (Single Answer)

What is Hot Java?

  1. Web browser from Sun Microsystem
  2. HTML Editor
  3. Java Editor
  4. Java Compiler
Question 17 Multiple Choice (Single Answer)

How many times will the body of the following loop execute? nt m = 10,n = 7; while(m%n>0) {… m = m+1; n = n + 2; …. }

  1. 4
  2. 3
  3. 0
  4. Infinite
Question 18 Multiple Choice (Single Answer)

Which of the following must be used to get 32, if the value of x is 32.9?

  1. Ceil(x)
  2. Round(x)
  3. Floor(x)
  4. Abs(x)
Question 19 Multiple Choice (Single Answer)

Throwing an expression always results in termination of the program.

  1. true
  2. false
  3. Depends on the exception.
  4. None
Question 20 Multiple Choice (Single Answer)

Use _________ option if the field is to be visible everywhere in the current package only.

  1. private
  2. public
  3. default
  4. protected
Question 21 Multiple Choice (Single Answer)

Declaring a class ______ prevents any unwanted extensions to the class.

  1. close
  2. terminate
  3. end
  4. final
Question 22 Multiple Choice (Single Answer)

Which of the following options is not an array declaration?

  1. float[ ] marks
  2. number = new int[5]
  3. int product [ ] [ ]
  4. float num{ }
Question 23 Multiple Choice (Single Answer)

Interfaces are used as _________, whose properties are inherited by classes.

  1. sub-classes
  2. super classes
  3. extended classes
  4. none of the above
Question 24 Multiple Choice (Single Answer)

Which one of the following is/are not used to suspend the thread temporarily?

  1. sleep()
  2. suspend()
  3. wait()
  4. all of the above
Question 25 Multiple Choice (Single Answer)

Which of the following statements are true?
i. An abstract class may not have any final methods.
ii. A final class may not have any abstract methods.
iii. An inner class may be declared with any accessibility keyword.
iv. Transient variables must be static.

  1. ii & iii
  2. i & ii
  3. i & iv
  4. iii & iv