Machine-translated by Google. Questions are authored in English.
Top

Language Fundamentals - General Questions Questions and Answers

1.

Which of the given options best describes the truthfulness of the following statements?

i) When a Java program is compiled, it generates Byte code.
ii) SOAP and RESTFUL are java web services.
iii) PATH Environment variable identifies the location of Java compiler.
iv) The || logical operator returns true if both statements are true.

Exam Year(s)

DSSSB TGT - 2023,

Answer: A

Statements i, ii and iii are true and iv is false. Compiling a Java program produces byte code, SOAP and RESTful are accepted in the key as Java web services, and the PATH environment variable gives the location of the Java compiler so that it can be run from any directory. The || operator is the logical OR, which returns true when at least one of the operands is true, and it is && that needs both to be true. So the fourth statement is false.

Please log in or register to report this question.

2.

What is the keyword final used for in Java ?

Exam Year(s)

Tripura Public Service Commission - 2025,

Answer: D

final is used for All of the above.

In Java, a final variable can be assigned only once, so it acts as a constant. A final method cannot be overridden by subclasses, which also makes it unmodifiable in them. (A final class cannot be extended.)

Since all three uses listed are correct, choosing any one alone is incomplete.

For example, final int MAX = 10; cannot be reassigned, and final class String cannot be subclassed.

Please log in or register to report this question.

3.

Which keyword is used to create an object in Java ?

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: D

Objects in Java are created with the new keyword.

new allocates memory for an object on the heap, calls the class constructor to initialise it, and returns a reference to it, as in Student s = new Student();.

create, object and make are not Java keywords. They could be used as ordinary identifiers, but none of them creates an object.

Please log in or register to report this question.

4.

Which is the method used to retrieve the current state of a check box ?

Exam Year(s)

UGC NET - 2012,

Answer: A

The method used to retrieve the current state of a check box is getState(), which returns true if the box is checked. The Java AWT Checkbox class has this method and also setState() to change the state. The names put State, retrieve State and write State are not methods of the class. The keyed answer is getState(). For example, cb.getState() returns true when the user has ticked the box and false when it is clear, and the program reads this value inside an event handler to decide what to do.

Please log in or register to report this question.

5.

Match the following interfaces of Java. Servlet package :

List - IList - II
a. Servlet Configi. Enables Servlets to log events
b. Servlet Contextii. Read data from a client
c. Servlet Requestiii. Write data to a client
d. Servlet Responseiv. To get initialization parameters

Codes : a b c d

Exam Year(s)

UGC NET - 2014,

Answer: D

The match is a-iv, b-i, c-ii, d-iii.

ServletConfig gets initialisation parameters, ServletContext lets servlets log events, ServletRequest reads data from a client and ServletResponse writes data to a client.

Code (D) gives these. The other codes give the config or context interface the request or response role. The Servlet API splits the work: ServletConfig is passed to init() and gives the servlet its initialisation parameters, ServletContext gives access to the web application and its log, ServletRequest is the way a servlet reads client data and ServletResponse is how it writes the reply.

Please log in or register to report this question.

Answer: A

Option A is correct. A public access modifier is acceptable. The method prototypes in an interface are all abstract by virtue of their declaration, and should not be declared abstract.

Option B is wrong. The final modifier means that this method cannot be constructed in a subclass. A final method cannot be abstract.

Option C is wrong. static is concerned with the class and not an instance.

Option D is wrong. protected is not permitted when declaring a method of an interface. See information below.

Member declarations in an interface disallow the use of some declaration modifiers; you cannot use transient, volatile, or synchronized in a member declaration in an interface. Also, you may not use the private and protected specifiers when declaring members of an interface.

Please log in or register to report this question.

7.

Which three are valid declarations of a char?

1.char c1 = 064770;

2.char c2 = 'face';

3.char c3 = 0xbeef;

4.char c4 = \u0022;

5.char c5 = '\iface';

6.char c6 = '\uface';

Answer: B

(1), (3), and (6) are correct. char c1 = 064770; is an octal representation of the integer value 27128, which is legal because it fits into an unsigned 16-bit integer. char c3 = 0xbeef; is a hexadecimal representation of the integer value 48879, which fits into an unsigned 16-bit integer. char c6 = '\uface'; is a Unicode representation of a character.

char c2 = 'face'; is wrong because you can't put more than one character in a char literal. The only other acceptable char literal that can go between single quotes is a Unicode value, and Unicode literals must always start with a '\u'.

char c4 = \u0022; is wrong because the single quotes are missing.

char c5 = '\iface'; is wrong because it appears to be a Unicode representation (notice the backslash), but starts with '\i' rather than '\u'.

Please log in or register to report this question.

Answer: D

The only legal array declaration and assignment statement is Option D

Option A is wrong because it initializes an int array with String literals.

Option B is wrong because it use something other than curly braces for the initialization.

Option C is wrong because it provides initial values for only one dimension, although the declared array is a two-dimensional array.

Please log in or register to report this question.

9.

What is the numerical range of a char?

Answer: D

Correct answer: 0 to 65535

A char is a 16-bit *unsigned* integral type, so it spans 0 to \( 2^{16}-1 = 65535 \) - the full range of UTF-16 code units. It is the only unsigned type in Java, which is why a char used in arithmetic promotes to int and why casting a negative int to char produces a large positive value rather than a negative one. The signed 16-bit range offered belongs to short.

Please log in or register to report this question.

10.

public interface Foo 
{ 
    int k = 4; /* Line 3 */
}

Which three piece of codes are equivalent to line 3?

1.final int k = 4;

2.public int k = 4;

3.static int k = 4;

4.abstract int k = 4;

5.volatile int k = 4;

6.protected int k = 4;

 

Answer: A

(1), (2) and (3) are correct. Interfaces can have constants, which are always implicitly public, static, and final. Interface constant declarations of public, static, and final are optional in any combination.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Language Fundamentals - General Questions Questions and Answers || Language Fundamentals - General Questions MCQ Questions and Answers || Language Fundamentals - General Questions GK Questions and Answers || Language Fundamentals - General Questions GK MCQ Questions || Language Fundamentals - General Questions Multiple Choice Questions and Answers || Language Fundamentals - General Questions GK || GK on Language Fundamentals - General Questions || Java Programming Questions and Answers || Java Programming MCQ Questions and Answers || Java Programming GK Questions and Answers || GK on Java Programming