0

programming languages Online Quiz - 180

Description: programming languages Online Quiz - 180
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0
  1. Domain

  2. Data element

  3. Technical settings

  4. None of the above


Correct Option: B

What is T-code for Database Utility?

  1. SE15

  2. SE14

  3. SE16

  4. SM30


Correct Option: B

The internal table itab1 has the following values Itab1-f1 10 20 50 30 70 .What is the output of the code? read table itab1 into v_tab index 3 binary search. if sy-subrc eq 0. write: v_tab-f1. endif.

  1. Syntax error

  2. 30

  3. Short dump

  4. No Output


Correct Option: A

In the where clause of select query having the non primary key fields Select….where A And B And C .Created a secondary index having A field first and D field next .Will Select query uses this secondary index?

  1. True

  2. False


Correct Option: A

REPORT ZTEST. statics: a(3) type c value ‘10’. data: b(3) type c value ‘10’. Do 5 times. perform add using a b. enddo. write: a,b. form ADD using a b. if sy-index eq 3. exit. else. a = a + 1. b = b + 1. endif. endform. " ADD What is the values of a and b?

  1. 10,13

  2. 10,14

  3. 14,14

  4. Syntax error


Correct Option: D

Which is the most suitable Java collection class for storing various companies and their stock prices? It is required that the class should support synchronization inherently.

  1. Hashtable

  2. Hashmap

  3. Linked Hashmap

  4. Hashset


Correct Option: A

int i = 3; switch (i) { default: System.out.println("default"); case 0: System.out.println("zero"); case 1: System.out.println("one"); break; case 2: System.out.println("two"); }

  1. default

  2. default, zero, one

  3. Compiler error

  4. No output displayed


Correct Option: B

Which of the following statements is not true about threads?

  1. If the start() method is invoked twice on the same Thread object, an exception is thrown at runtime.

  2. The order in which threads were started might differ from the order in which they actually run.

  3. If the run() method is directly invoked on a Thread object, an exception is thrown at runtime.

  4. If the sleep() method is invoked on a thread while executing synchronized code, the lock is not released.


Correct Option: C
Explanation:

To answer this question one needs to know about threads in programming. Threads are the smallest unit of execution that can be scheduled by an operating system. Each thread represents a separate flow of control. Threads are lightweight compared to processes, and they share memory with other threads in the same process.

Now let's go through each option and explain why it is true or false:

A. If the start() method is invoked twice on the same Thread object, an exception is thrown at runtime.

This statement is true. If the start() method is invoked twice on the same Thread object, an exception (IllegalThreadStateException) is thrown at runtime.

B. The order in which threads were started might differ from the order in which they actually run.

This statement is true. The operating system schedules threads based on its own algorithm, which might differ from the order in which the threads were started.

C. If the run() method is directly invoked on a Thread object, an exception is thrown at runtime.

This statement is false. If the run() method is directly invoked on a Thread object, the run() method will execute just like any other method. However, it will not start a new thread of execution, and any other code that is waiting for the thread to complete will not be notified.

D. If the sleep() method is invoked on a thread while executing synchronized code, the lock is not released.

This statement is true. When a thread invokes the sleep() method while executing synchronized code, the lock associated with the synchronized code is not released. This means that other threads that require the same lock will have to wait until the sleeping thread releases the lock.

Therefore, the correct answer is: C. If the run() method is directly invoked on a Thread object, an exception is thrown at runtime.

The concept of hiding the implementation details of a class and allowing access to the class through a public interface is called as

  1. Encapsulation

  2. Polymorphism

  3. Overloading

  4. Overriding


Correct Option: A

The '&' operator in java

  1. sets a bit to 1 if both operand's bits are 1

  2. sets a bit to 1 if only one operand's bit is 1.

  3. sets a bit to 1 if at least one operand's bit is 1

  4. reverses the value of every bit in the operand


Correct Option: A

Select the new keyword since J2SE 1.4

  1. abstract

  2. assert

  3. synchronized

  4. strictfp


Correct Option: B

Assume the bit pattern of byte x is: 10110001. What will the sign of x be after x>>2?

  1. postive

  2. negative

  3. can't be find

  4. none of the above


Correct Option: B

What happens when you compare two primitives of different numerical types?

  1. compiler error

  2. smaller type is promoted

  3. must explicitly cast

  4. none of the above


Correct Option: B

All exceptions inherit from

  1. java.lang.Exception

  2. java.lang.Error

  3. java.lang.Throwable

  4. none of the above


Correct Option: C

package polymorphism; class TestSup { static int p = 100; } public class TestPoly extends TestSup { public static void main(String[] args) { TestPoly TP = new TestPoly(); TP.p = 400; TestSup TS = new TestSup(); TS.p = 100; TestSup TSP = new TestPoly(); TSP.p = 500; System.out.print("TestSup = " + TestSup.p); System.out.print(" ,TestPoly = " + TestPoly.p); System.out.print(" ,TP = " + TP.p); System.out.print(" ,TS = " + TS.p); System.out.print(" ,TSP = " + TSP.p); } }

  1. TestSup = 100 ,TestPoly = 400 ,TP = 500 ,TS = 500 ,TSP = 500

  2. TestSup = 500 ,TestPoly = 500 ,TP = 500 ,TS = 500 ,TSP = 500

  3. TestSup = 100 ,TestPoly = 400 ,TP = 400 ,TS = 100 ,TSP = 500

  4. TestSup = 500 ,TestPoly = 400 ,TP = 500 ,TS = 100 ,TSP = 400


Correct Option: B

package polymorphism; class TestPolymorphismSuper { int p; TestPolymorphismSuper testPoly() { TestPolymorphismSuper TS = new TestPolymorphismSuper(); TS.p =100; return TS; } } public class TestPolymorphism1 extends TestPolymorphismSuper{ TestPolymorphism1 testPoly() { TestPolymorphism1 TSub = new TestPolymorphism1(); TSub.p =500; return TSub; } public static void main(String[] args) { TestPolymorphismSuper TSuper = new TestPolymorphism1(); TSuper = TSuper.testPoly(); System.out.println(TSuper.p); } }

  1. 500

  2. 100

  3. 0

  4. Null Pointer Exception


Correct Option: A

package polymorphism; class TestPolymorphismSuper1 { String name; TestPolymorphism2 testPoly() { TestPolymorphism2 TS = new TestPolymorphism2(); TS.name ="tcs"; return TS; } } public class TestPolymorphism2 extends TestPolymorphismSuper1{ TestPolymorphism2 testPoly() { TestPolymorphism2 TSub = new TestPolymorphism2(); TSub.name = "UX"; return TSub; } public static void main(String[] args) { TestPolymorphismSuper1 TSuper = new TestPolymorphism2(); TSuper.testPoly(); System.out.println(TSuper.name); } }

  1. tcs

  2. UX

  3. null

  4. Exception


Correct Option: C

package polymorphism; class TestSuperr { double TestPoly(long a, float b, int c) { return ((a + b) * c); } } public class TestPolym extends TestSuperr { double TestPoly(long a, double b, int c) { return (a + b + c); } public static void main(String[] args) { TestSuperr TSU = new TestPolym(); double p = TSU.TestPoly(11, 9, 10); System.out.print("p = " + p); p1 = TSU.TestPoly(11, 9.0, 10); System.out.print(" ,p1 = " + p1); } }

  1. Compiler Error

  2. p = 200.0, p1 = 30.0

  3. p = 200.0, p1 = 200.0

  4. p = 30.0, p1 = 30.0


Correct Option: A

package polymorphism; class TestSupe { static int p = 100; } public class TestPoly1 extends TestSupe { static int p =1000; public static void main(String[] args) { TestPoly1 TP = new TestPoly1(); TP.p = 400; TestSupe TS = new TestSupe(); TS.p = 300; TestSupe TSP = new TestPoly1(); TSP.p = 500; System.out.print("TestSupe = " + TestSupe.p); System.out.print(" ,TestPoly = " + TestPoly1.p); System.out.print(" ,TP = " + TP.p); System.out.print(" ,TS = " + TS.p); System.out.print(" ,TSP = " + TSP.p); } }

  1. TestSupe = 300 ,TestPoly = 400 ,TP = 400 ,TS = 300 ,TSP = 500

  2. TestSupe = 500 ,TestPoly = 400 ,TP = 400 ,TS = 500 ,TSP = 500

  3. TestSupe = 500 ,TestPoly = 400 ,TP = 400 ,TS = 300 ,TSP = 500

  4. TestSupe = 300 ,TestPoly = 400 ,TP = 500 ,TS = 500 ,TSP = 500


Correct Option: B

AI Explanation

To answer this question, we need to understand the concept of static variables and inheritance in Java.

In the given code, there are two classes: TestSupe and TestPoly1. TestPoly1 extends TestSupe, which means that TestPoly1 inherits all the variables and methods from TestSupe.

Let's go through each option to understand why it is correct or incorrect:

Option A) TestSupe = 300, TestPoly = 400, TP = 400, TS = 300, TSP = 500 This option is incorrect. Although the values of p are modified in different instances, the static variable p belongs to the class itself, not to its instances. Therefore, the value of p will be the same for all instances of the class.

Option B) TestSupe = 500, TestPoly = 400, TP = 400, TS = 500, TSP = 500 This option is correct. The static variable p in TestSupe is modified to 300, but then it is modified to 500 when accessing it through an instance of TestPoly1 (TSP.p). The static variable p in TestPoly1 is set to 400 and remains the same. The variable p in the instance TP is set to 400, and the variable p in the instance TS is set to 500.

Option C) TestSupe = 500, TestPoly = 400, TP = 400, TS = 300, TSP = 500 This option is incorrect. The value of TS.p is modified to 300, but the value of TSP.p is modified to 500. This suggests that TSP is an instance of TestPoly1, so the value of TestPoly1.p should be 500, not 400.

Option D) TestSupe = 300, TestPoly = 400, TP = 500, TS = 500, TSP = 500 This option is incorrect. The value of TP.p is modified to 400, and the value of TS.p is modified to 500. This suggests that TS is an instance of TestPoly1, so the value of TestPoly1.p should be 500, not 400.

The correct answer is Option B.

- Hide questions