A Practice Test On JavaScript! Hardest Trivia Questions Quiz

40 Questions

Settings
Please wait...
A Practice Test On JavaScript! Hardest Trivia Questions Quiz

If you are looking for a practice test on JavaScript, you are in luck as the hardest trivia questions quiz below is perfect for seeing how much you understand the programming language. If you fail to get at least half the marks, you should consider a person who will help you learn some more about Java. All the best tackling it!


Questions and Answers
  • 1. 
    What will be displayed in jTextField1 after executing the following code? int m=16; m = --m + --m/3; if(m<15)       jTextField1.setText(Integer.toString(--m)); else      jTextField1.setText(Integer.toString(++m));
    • A. 

      20

    • B. 

      21

    • C. 

      22

    • D. 

      19

  • 2. 
    What message will be displayed after the execution of the following code?   int age = 64, relaxation =4; int ModiAge=age-relaxation++; if(ModiAge<60)     JOptionPane.showMessageDialog(null, "Not Eligible"); else       JOptionPane.showMessageDialog(null, "Not Eligible");
    • A. 

      Eligible

    • B. 

      Not Eligible

  • 3. 
    What will be displayed in jTextArea1 after executing the following statement? jTextArea1.setText("Special Observer\nSh. Mrinal Kanti Das IPS\tby ECI");
    • A. 

      Special Observer Sh. Mrinal Kanti Das IPS    by EC

    • B. 

      Special ObserverSh. Mrinal Kanti Das IPS     by EC

  • 4. 
    Given a string object named Pay having value as “68000” stored in it.  Obtain the output of the following: String Pay="68000";   JOptionPane.showMessageDialog(null,                                                   ""+(Pay.length()+Integer.parseInt(Pay)));
    • A. 

      68005

    • B. 

      680005

  • 5. 
    A phone number, consisting of 10 digits is stored in a string variable strPhone.  Now it is required to store this phone number in a Long type variable lngPhone.  Write a java statement to do this.
    • A. 

      String phonenumner ="2934568000";   lngPhone =long.parseLong(phonenumner);

    • B. 

      String phonenumner ="2934568000";  long lngPhone =long.parseLong(phonenumner);

  • 6. 
    What will be the content of jTextField1 after executing the following code. int Num=16; Num/=3; if(Num>5)   jTextField1.setText(Integer.toString(Num)); else   jTextField1.setText(Integer.toString(Num+5)); System.out.println("Num = "+Num);
    • A. 

      10

    • B. 

      11

    • C. 

      9

    • D. 

      12

  • 7. 
    What will be the content of jTextArea1 after the execution of the following statements? jTextArea1.setText("Cyrus\tPoonawalla\nto be honoured"); String Subject="Rahat Khan"; jTextArea1.append((Subject.length()+10)+"");
    • A. 

      Cyrus Poonawalla to be honoured20

    • B. 

      Cyrus Poonawallato be honoured20

  • 8. 
    What will be displayed in jTextField1 and jTextField2 after the execution of the following code? int Last, First=3,Second=5; Last=++First + Second++; jTextField1.setText(Integer.toString(Last++)); jTextField2.setText(Integer.toString(++Second));
    • A. 

      97

    • B. 

      79

  • 9. 
    What will be the contents of str1 and str2 after the following code is executed?   String str1, str2; str1="Indian Army"; str2 = "Mountaineering"; str1 = str2.concat(str1);
    • A. 

      MountaineeringIndianArmy

    • B. 

      MountaineeringIndian Army

  • 10. 
    Write a statement in Java to declare a String type variable with a name City.
    • A. 

      String City;

    • B. 

      Char City;

  • 11. 
    What will be the value X1 after execution of the following code: String x1="Sunderbans", x2="to Dhaka";          x1=x1.concat(x2);
    • A. 

      Sunderbansto Dhaka

    • B. 

      SunderbanstoDhaka

  • 12. 
    Give the output of the following Java code:   String name="Azali Asssoumani"; int TM=name.length(), TN; TN=80-TM; jTextField1.setText (Integer.toString (TM)); jTextField2.setText (Integer.toString (TN));
    • A. 

      17   // jTextField163   // jTextField2

    • B. 

      16   // jTextField164   // jTextField2

  • 13. 
    Give the output of the following java code i   String na= "Seamaster 2019" ; int T=na.length(),N; N=150-T; jTextField1.setText(Integer.toString(T)) ; jTextField2.setText(Integer.toString(N)) ;
    • A. 

      15     //jTextField1137  // jTextField2

    • B. 

      14     //jTextField1136  // jTextField2

  • 14. 
    Write the value of z after execution of following code : int j; int z; j=4; z = j+ (4*++j)%3-j;
    • A. 

      1

    • B. 

      2

    • C. 

      3

    • D. 

      4

  • 15. 
    What will be the content of the jTextArea1 after executing the following code :  int n = 89; jTextArea1.setText(Integer.toString(++n+n));
    • A. 

      180

    • B. 

      181

    • C. 

      182

    • D. 

      183

  • 16. 
    In a java program Rajat wants to use a variable to store the quantity of an item which may be in whole numbers or decimals. Write a suitable java statement to declare the variable for the above mentioned purpose.
    • A. 

      Double qty;

    • B. 

      Int qty;

  • 17. 
    Given a String object named 'code' having value as “908” stored in it. What will be the result of the following? String code="908";         JOptionPane.showMessageDialog(null, " " +(code.length( )+ Integer.parseInt(code)));
    • A. 

      911

    • B. 

      3908

  • 18. 
    What will be displayed in jTextField1 and jTextField2 after the following code is executed:   int num = 35 , num1 = 46 ; jTextField1.setText( num + num1 + " " ) ; jTextField2.setText( " " + num + num1 ) ;
    • A. 

      803545

    • B. 

      813546

  • 19. 
    Write the value of t after the execution of the following code. int t; int s; s=6; t=(8*s++)%7-s; System.out.println(t);
    • A. 

      1

    • B. 

      -1

  • 20. 
    Write the value of variable ‘c’ after execution of the following code : int d; int c; d=7; c = ++d+(5*++d)%3;
    • A. 

      C=9

    • B. 

      C=8

  • 21. 
    Int d; int c; d=7; c = (5*++d)%3+ ++d; System.out.println("c= "+c);
    • A. 

      C=10

    • B. 

      C=8

  • 22. 
    Write the values of sum and x after execution of the following code : int sum, x; sum = 7; x = 5; sum = sum + (x++);
    • A. 

      Sum= 12

    • B. 

      Sum= 11

  • 23. 
    Write the values of sum and t after execution of the following code. int sum,t; sum=27; t=3; sum=sum+2*(++t);
    • A. 

      Sum= 35

    • B. 

      Sum= 34

  • 24. 
    What will be displayed in jTextField1 and jTextField2 after the  following code is executed:   int t; int x; x=12; t=(3*x++)/3 + ++x%2; jTextField1.setText(""+t); jTextField2.setText(""+x);
    • A. 

      12   // jTextField114    // jTextField2

    • B. 

      13   // jTextField114    // jTextField2

  • 25. 
    Write Java code (statements) to declare Y as integer variable. Then, assign the value 30 to a variable Y. Increase the value of Y by 5 and store the increased value in Z.
    • A. 

      Int Y=30; Y+=5;Z=Y;

    • B. 

      Int Y=30; Y=5;Z=Y;

  • 26. 
    Write the values of r and s after execution of following code: int p = 11; int q = 21; int r, s; p/=2; q%=2; r = ++q; s = p++; r++;
    • A. 

      R= 2s= 5

    • B. 

      R= 3s= 5

  • 27. 
    Write the value that will be assigned to variable C after executing the following statement: C = 25-5*4/2-10%4;
    • A. 

      13

    • B. 

      14

  • 28. 
    Write Java code to assign the value 10 to variable x and store its square value in another variable y.
    • A. 

      Int x=10, y=x+x;

    • B. 

      Int x=10, y=x*x;

  • 29. 
    What will be displayed in jTextField1 and jTextField2 after the following code is executed:    int number = 12; if (number <15) { jTextField1.setText(""+ number) ; number++; jTextField2.setText(""+ number) ; } else { jTextField1.setText(""+number) ; number++; jTextField2.setText(""+number) ; }
    • A. 

      13     //jTextField113    //jTextField2

    • B. 

      12    //jTextField113   //jTextField2

  • 30. 
    Consider the statement : fname = “Rishabh”; (i) What is the datatype of fname ? (ii) Is 456 the same as “456” ? Give reason.
    • A. 

      I)Stringii)No 456 is int data type"456" is String data type

    • B. 

      Intii)No 456 is int data type"456" is String data type

  • 31. 
    Write the values of num2 and num3 after execution of following code : int num1, num2, num3; num1 = 100; num2 = ++num1; num3 = num2++ + ++num1;
    • A. 

      Num2=103num3=203

    • B. 

      Num2=102num3=203

  • 32. 
    Write the data type of variables that should be used to store : (i) incentives given to salesperson (ii) Name of Salesperson
    • A. 

      I)intii)String

    • B. 

      I)floatii)String

  • 33. 
    Write the value that will be stored in variable a after execution of the following code if : (i) initial value of a is 18. (ii) initial value of a is 20. int b = 9; if (a > b)   a=a+5; else    a=a+2;
    • A. 

      I)23ii)26

    • B. 

      I)23ii)25

  • 34. 
    Ms. Meena is not able to understand the statement “Java is a case sensitive language”. Help her in understanding the above mentioned statement by giving suitable example.
    • A. 

      Int Sum, sum, SUM;   //Java treats each of this as  different variables

    • B. 

      Int Sum, sum, SUM;   //Java treats each of this as  samevariables

  • 35. 
    Write Java code to declare a variable named Price of integer type. Assign a value 10 to this variable. Overwrite the value of price with its double value. Decrease the value of price by 5.
    • A. 

      Int Price; Price=10; price=price*price; price=price-5;

    • B. 

      Int Price;  price=price*price; price=price-5;

  • 36. 
    Identify the invalid variable names. State the reason if invalid. (i) Marks Unit (ii) Product_1 (iii) Sales123 (iv) 2Marks
    • A. 

      I and iii

    • B. 

      I and iv

  • 37. 
    Write the data type of variables that should be used to store: (i) Marks of students (ii) Grades of students(Grade can be ‘A’ or ‘B’ or ‘C’)
    • A. 

      Float or doublechar

    • B. 

      Byte or intchar

  • 38. 
    Write examples of any two properties and any two methods of jButton component
    • A. 

             Name and text and setText(), isEnabled()                 

    • B. 

             editable and text and setText(), isEnabled()                 

  • 39. 
    Write the value that will be stored in variable a after execution of the following code if: (i) initial value of a is 18. (ii) initial value of a is 20. int b = 9; if (a > b)     a=a+5; a=a+2;
    • A. 

      I ) 24ii) 27

    • B. 

      I ) 25ii) 27

  • 40. 
    Int A=20,B=30,BIG; BIG = A>B?A:B; What will be assigned in BIG Hint : ? is the ternary operator, if a>b then a is assigned to big otherwise b is assigned to big
    • A. 

      30

    • B. 

      30