Java Multiple Choice Questions & Answers on Arithmetic Operators for Freshers

1. Which of the following can be operands of arithmetic operators?

a) Numeric
b) Boolean
c) Characters
d) Both Numeric & Characters

Answer:d

Explanation: The operand of arithmetic operators can be any of numeric or character type, But not boolean.
2. Modulus operator, %, can be applied to which of these?

a) Integers
b) Floating – point numbers
c) Both Integers and floating – point numbers.
d) None of the mentioned
Answer:c

Explanation: Modulus operator can be applied to both integers and floating point numbers. .
3. With x = 0, which of the following are legal lines of Java code for changing the value of x to 1?
1. x++;
2. x = x + 1;
3. x += 1;
4. x =+ 1;

a) 1, 2 & 3
b) 1 & 4
c) 1, 2, 3 & 4
d) 3 & 2
Answer: c

Explanation: Operator ++ increases value of variable by 1. x = x + 1 can also be written in shorthand form as x += 1. Also x =+ 1 will set the value of x to 1.
4. Decrement operator, −−, decreases value of variable by what number?

a) 1
b) 2
c) 3
d) 4
Answer: a
5. Which of these statements are incorrect?

a) Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms.
b) Assignment operators run faster than their equivalent long forms.
c) Assignment operators can be used only with numeric and character data type.
d) None
Answer: d
6. What is the output of this program?
  1.     class increment {
  2.         public static void main(String args[])
  3.         {
  4.             double var1 = 1 + 5; 
  5.             double var2 = var1 / 4;
  6.             int var3 = 1 + 5;
  7.             int var4 = var3 / 4;
  8.             System.out.print(var2 + " " + var4);
  9.  
  10.         } 
  11.     }
a) 1 1
b) 0 1
c) 1.5 1
d) 1.5 1.0
Answer:c
7. What is the output of this program?
  1.     class Modulus {
  2.         public static void main(String args[]) 
  3.         {    
  4.              double a = 25.64;
  5.              int  b = 25;
  6.              a = a % 10;
  7.              b = b % 10;
  8.              System.out.println(a + " "  + b);
  9.         } 
  10.     }
a) 5.640000000000001 5
b) 5.640000000000001 5.0
c) 5 5
d) 5 5.640000000000001
Answer: a

Explanation: Modulus operator returns the remainder of a division operation on the operand. a = a % 10 returns 25.64 % 10 i:e 5.640000000000001. Similarly b = b % 10 returns 5.
8. What is the output of this program?
  1.     class increment {
  2.         public static void main(String args[]) 
  3.         {        
  4.              int g = 3;
  5.              System.out.print(++g * 8);
  6.         } 
  7.     }
a) 25
b) 24
c) 32
d) 33
Answer:c

Explanation: Operator ++ has more preference than *, thus g becomes 4 and when multiplied by 8 gives 32.
9. Can 8 byte long data type be automatically type cast to 4 byte float data type?

a) True
b) False
Answer: a

Explanation: Both data types have different memory representation that’s why 8-byte integral data type can be stored to 4-byte floating point data type.
10. What is the output of this program?
  1.     class Output {
  2.         public static void main(String args[]) 
  3.         {    
  4.              int a = 1;
  5.              int b = 2;
  6.              int c;
  7.              int d;
  8.              c = ++b;
  9.              d = a++;
  10.              c++;
  11.              b++;
  12.              ++a;
  13.              System.out.println(a + " " + b + " " + c);
  14.         } 
  15.     }
a) 3 2 4
b) 3 2 3
c) 2 3 4
d) 3 4 4
Answer: d

Related

Objective type Questions for Computer Science Students

1) The time for which a piece of equipment operates is called? a)Seek time b)Effective time c)Access time d)Real time e)None of the above Answer:   b 2) ____ is an area of a co...

Apache Flex Objective Questions for Interviews

Apache Flex Objective Questions  1. True or False? You can apply skins to components using CSS. A. TrueB. FALSE Ans: A 2. How will you call Java method from Flex? A. HttpserviceB. Rem...

ASP Dotnet Objective Questions and Answers

1. Choose the form in which Postback occur A. HTMLFormsB. WebformsC. Winforms Ans: Webforms 2. Web.config file is used A. Configures the time that the server-side codebehind module is calledB. T...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item