IndiaBIX
IndiaBIX
Start typing & press "Enter" or "ESC" to close
  • Home
  • Jobs
  • Results
  • Current Affairs
  • GK
  • Online Test
  • HR Interview
  • BLOG

Language Fundamentals - General Questions

  • Home
  • Computer Science & Engineering
  • Java Programming Questions and Answers
  • Language Fundamentals - General Questions
1. 

What is the numerical range of a char?

A. -128 to 127
B. -(215) to (215) - 1
C. 0 to 32767
D. 0 to 65535

Answer: Option D

Explanation:

A char is really a 16-bit integer behind the scenes, so it supports 216 (from 0 to 65535) values.
View Answer Discuss Workspace Report

2. 

Which is a valid declarations of a String?

A. String s1 = null;
B. String s2 = 'null';
C. String s3 = (String) 'abc';
D. String s4 = (String) '\ufeed';

Answer: Option A

Explanation:

Option A sets the String reference to null.

Option B is wrong because null cannot be in single quotes.

Option C is wrong because there are multiple characters between the single quotes ('abc').

Option D is wrong because you can't cast a char (primitive) to a String (object).

View Answer Discuss Workspace Report

3. 

Which three are valid declarations of a float?

1 float f1 = -343;

2 float f2 = 3.14;

3 float f3 = 0x12345;

4 float f4 = 42e7;

5 float f5 = 2001.0D;

6 float f6 = 2.81F;

A. 1, 2, 4
B. 2, 3, 5
C. 1, 3, 6
D. 2, 4, 6

Answer: Option C

Explanation:

(1) and (3) are integer literals (32 bits), and integers can be legally assigned to floats (also 32 bits). (6) is correct because (F) is appended to the literal, declaring it as a float rather than a double (the default for floating point literals).

(2), (4),and (5) are all doubles.

View Answer Discuss Workspace Report

4. 

Which one is a valid declaration of a boolean?

A. boolean b1 = 0;
B. boolean b2 = 'false';
C. boolean b3 = false;
D. boolean b4 = Boolean.false();
E. boolean b5 = no;

Answer: Option C

Explanation:

A boolean can only be assigned the literal true or false.
View Answer Discuss Workspace Report

5. 

Which is the valid declarations within an interface definition?

A. public double methoda();
B. public final double methoda();
C. static void methoda(double d1);
D. protected void methoda(double d1);

Answer: Option A

Explanation:

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.

View Answer Discuss Workspace Report

6. 

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';

A. 1, 2, 4
B. 1, 3, 6
C. 3, 5
D. 5 only

Answer: Option B

Explanation:

(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'.

View Answer Discuss Workspace Report

7. 

Which one of the following will declare an array and initialize it with five numbers?

A. Array a = new Array(5);
B. int [] a = {23,22,21,20,19};
C. int a [] = new int[5];
D. int [5] array;

Answer: Option B

Explanation:

Option B is the legal way to declare and initialize an array with five elements.

Option A is wrong because it shows an example of instantiating a class named Array, passing the integer value 5 to the object's constructor. If you don't see the brackets, you can be certain there is no actual array object! In other words, an Array object (instance of class Array) is not the same as an array object.

Option C is wrong because it shows a legal array declaration, but with no initialization.

Option D is wrong (and will not compile) because it declares an array with a size. Arrays must never be given a size when declared.

View Answer Discuss Workspace Report

8. 

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;

A. 1, 2 and 3
B. 2, 3 and 4
C. 3, 4 and 5
D. 4, 5 and 6

Answer: Option A

Explanation:

(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.

View Answer Discuss Workspace Report

  • 1
  • 2

Questions & Answers

Aptitude Chemical Engineering Civil Engineering Computer Science & Engineering Current Affairs Data Interpretation Electrical & Electronics Engineering Electronics & Communication Engineering General Knowledge Logical Reasoning Mechanical Engineering Non Verbal Reasoning Verbal Ability Verbal Reasoning

Interviews

HR Interview

Jobs

Sarkari Jobs

Results

Rojgar ResultSarkari Result

Admission

Admission 2023

Admit Card

Admit Card 2023

Answer Key

Answer Key 2023
copyright
Privacy Policy
© 2025 IndiaBIX. All Rights Reserved.

Report