Tag: programming languages

Questions Related to programming languages

  1. A 12

  2. B 012

  3. C 10

  4. D 10.0


Correct Option: C
Explanation:

To solve this question, the user needs to know the basics of Java programming language. The code creates an object of the Oct class and then calls the amethod() method, which initializes an integer variable oi with 012 and prints its value to the console.

In Java, leading zero in an integer literal denotes an octal (base-8) number. Therefore, the value 012 is an octal number that represents the decimal value 10.

So, the correct answer is:

The Answer is: C. 10

13 Which of the following statements are true?

  1. a. The elements in a Java array can only be of primitive types, not objects

  2. b. Arrays elements are initialized to default values wherever they are created using the keword new

  3. c. An array may be dynamically resized using the setSize method

  4. d. You can find out the size of an array using the size method


Correct Option: B
  1. a float f=1/3;

  2. b int i=1/3;

  3. c float f=1.01;

  4. d double d=999d;


Correct Option: A,B,D
  1. A System.out.println(1+1);

  2. B int i=2+'2';

  3. C String s="on"+'one';

  4. D byte b=255;


Correct Option: A,B

16 Which of the following statements are true?

  1. a. All of the variables in an interface are implicitly static

  2. b. All of the variables in an interface are implicitly final

  3. c. All of the methods in an interface are implicitly abstract

  4. d. A method in an interface can access class level variables


Correct Option: A,B,C

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) All of the variables in an interface are implicitly static - This option is true. In an interface, all variables are implicitly static, meaning they belong to the interface itself rather than any specific instance.

Option B) All of the variables in an interface are implicitly final - This option is true. In an interface, all variables are implicitly final, meaning their values cannot be changed once they are assigned.

Option C) All of the methods in an interface are implicitly abstract - This option is true. In an interface, all methods are implicitly abstract, meaning they do not have a body and must be implemented by any class that implements the interface.

Option D) A method in an interface can access class-level variables - This option is false. Methods in an interface can only access variables declared within the interface itself. They cannot access variables from implementing classes or any other classes.

The correct answer is A, B, C. These options are correct because variables in an interface are implicitly static and final, and methods in an interface are implicitly abstract.

17 Which of the following statements are true?

  1. a. An interface can only contain method and not variables

  2. b. Interfaces cannot have constructors

  3. c. A class may extend only one other class and implement only one interface

  4. d. Interfaces are the Java approach to addressing its lack of multiple inheritance, but require implementing classes to create the functionality of the Interfaces.


Correct Option: B

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) An interface can only contain methods and not variables - This option is incorrect. Interfaces can contain both methods and variables. In Java, interface variables are by default public, static, and final.

Option B) Interfaces cannot have constructors - This option is correct. Interfaces cannot have constructors because they are not meant to be instantiated directly. They are used as a blueprint for classes that implement them.

Option C) A class may extend only one other class and implement only one interface - This option is incorrect. In Java, a class can extend only one other class, but it can implement multiple interfaces. This is known as multiple interface inheritance.

Option D) Interfaces are the Java approach to addressing its lack of multiple inheritance, but require implementing classes to create the functionality of the interfaces - This option is incorrect. Interfaces in Java are used for abstraction and defining contracts. They do not provide functionality themselves. Implementing classes are responsible for providing the implementation of the methods defined in the interface.

The correct answer is B) Interfaces cannot have constructors.

19 Read this piece of code carefully if("String".toString() == "String") System.out.println("Equal"); else System.out.println("Not Equal");

  1. a. the code will compile an print "Equal".

  2. b. the code will compile an print "Not Equal".

  3. c. the code will cause a compiler error.

  4. d.


Correct Option: B
  1. a. the code will compile an print "Equal".

  2. b. the code will compile an print "Not Equal".

  3. c. the code will cause a compiler error

  4. d.


Correct Option: A