Tag: core java

Questions Related to core java

Which of them is a not command line Tool?

  1. 1.java

  2. 2.javaw

  3. 3.javapath

  4. 4.javadoc


Correct Option: C

AI Explanation

To answer this question, you need to understand the concept of command line tools. Command line tools are programs or applications that can be executed from the command line interface of an operating system.

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

Option A) 1.java - This option is incorrect because "java" is a command line tool for running Java programs.

Option B) 2.javaw - This option is incorrect because "javaw" is also a command line tool for running Java programs, specifically Java programs that don't display a console window.

Option C) 3.javapath - This option is correct because "javapath" is not a recognized command line tool. It does not exist as a standard command for executing tasks in the command line interface.

Option D) 4.javadoc - This option is incorrect because "javadoc" is a command line tool that generates Java API documentation.

The correct answer is C) 3.javapath. This option is correct because "javapath" is not a recognized command line tool.

A/An___instance variable is shared by all instances of the class.It exist even before the object is created

  1. 1.instance

  2. 2.abstract

  3. 3.interface

  4. 4.static


Correct Option: A

AI Explanation

To answer this question, you need to understand the concept of instance variables in object-oriented programming.

An instance variable is a variable that is declared within a class and is associated with individual instances (objects) of that class. Each instance of the class has its own copy of the instance variable, and changes made to the variable within one instance do not affect the variable in other instances.

However, the correct answer to this question is option A) 1. instance. This is because an instance variable is not shared by all instances of the class. Instead, it is unique to each instance. It is created and initialized when an object is created and exists as long as the object exists.

Option B) 2. abstract, option C) 3. interface, and option D) 4. static are incorrect answers for this question because they do not describe an instance variable. Abstract and interface are concepts related to defining the behavior of classes and cannot be used to declare variables. Static variables, on the other hand, are shared by all instances of a class, but they are not instance variables. Static variables belong to the class itself and are initialized once, regardless of the number of instances created.

Therefore, the correct answer is option A) 1. instance, as it correctly describes an instance variable that is unique to each object and exists even before the object is created.

Which of the following is not a method of java.util.ArrayList?

  1. 1.add(Object x)

  2. 2.remove(Object x)

  3. 3.contains(Object x)

  4. 4.insert(int i,Object x)

  5. 5.set(int I,Object x)


Correct Option: D
  1. 1.information hiding

  2. 2.encapsulation

  3. 3.Inheritance

  4. 4.modularity


Correct Option: B
Explanation:

To solve this question, the user needs to be familiar with the concepts of object-oriented programming and the principles of encapsulation and information hiding.

Now, let's go through each option and explain why it is right or wrong:

A. 1. information hiding: This option is correct. Information hiding is the practice of encapsulating the internal details of an object and providing access to it only through its member functions. This helps to hide the complexity and implementation details of an object, allowing for better maintainability and preventing unauthorized access to sensitive information.

B. 2. encapsulation: This option is correct. Encapsulation is the practice of bundling data and methods together within a class and providing controlled access to them. It allows for the implementation details of an object to be hidden and accessed only through the defined interface, promoting modularity and code reusability.

C. 3. Inheritance: This option is incorrect. Inheritance is a concept in object-oriented programming where a class derives properties and behaviors from another class. It is not directly related to the practice of providing access to an object only through its member functions and keeping the details private.

D. 4. modularity: This option is incorrect. Modularity refers to the practice of dividing a program into smaller, independent modules that can be developed, tested, and maintained separately. While encapsulation and information hiding contribute to modularity, modularity does not specifically refer to the practice of providing access to an object only through its member functions and keeping the details private.

The Answer is: B. 2. encapsulation

Which of the following best descibes the set of all paires of values for boolean variables a and b such that, (!a && b)==!(a||b) evaluates to true?

  1. 1.Empty set

  2. 2.one pair a==true,b==false

  3. 3.two pairs in which a==true

  4. 4.two paires in which a!=b

  5. 5.All 4possible combination


Correct Option: C
  1. 1.static,nonstatic class

  2. 2.Inheritance,Composition

  3. 3.Composition,Inheritance

  4. 4.Overriding,Overloading


Correct Option: C

What is the default layout manager for a panel?

  1. 1.BorderLayout

  2. 2.Ther is no layout

  3. 3.FlowLayout

  4. 4.GridLayout


Correct Option: A

What happens in a method if an unchecked exception is thrown in a try block and there is no matching catch block?

  1. 1.program ignores exceptn

  2. 2.program halts immediately

  3. 3.Program will not compile

  4. 4.None of the above


Correct Option: B

AI Explanation

To answer this question, you need to understand how exception handling works in Java.

When an unchecked exception is thrown in a try block and there is no matching catch block, the program will halt immediately.

Option A) 1. The program ignores the exception - This option is incorrect because when an exception is thrown and there is no matching catch block, the program does not ignore the exception. Instead, it halts immediately.

Option B) 2. The program halts immediately - This option is correct. When an unchecked exception is thrown and there is no matching catch block, the program will halt immediately.

Option C) 3. The program will not compile - This option is incorrect. The program will still compile even if there is no catch block for an unchecked exception.

Option D) 4. None of the above - This option is incorrect. Option B is the correct answer.

The correct answer is B) 2. The program halts immediately because there is no matching catch block for the unchecked exception.

Which are the values in arr after execution of following.. Int[]arr={1,1,0,0,0}; for(int i=2;i < arr.length;i++) arr[i]=arr[i-1]+arr[i-2];

  1. 1.11011

  2. 2.1121

  3. 3.11222

  4. 4.11235

  5. 5.11248


Correct Option: D

AI Explanation

To determine the values in the array arr after executing the given code, let's go through each iteration of the loop:

  1. Before the loop starts: arr = [1, 1, 0, 0, 0]
  2. Iteration 1: arr[2] = arr[1] + arr[0], so arr[2] = 1 + 1 = 2 Updated arr = [1, 1, 2, 0, 0]
  3. Iteration 2: arr[3] = arr[2] + arr[1], so arr[3] = 2 + 1 = 3 Updated arr = [1, 1, 2, 3, 0]
  4. Iteration 3: arr[4] = arr[3] + arr[2], so arr[4] = 3 + 2 = 5 Updated arr = [1, 1, 2, 3, 5]

After executing the code, the final value of arr is [1, 1, 2, 3, 5].

Among the given options, the correct answer is D) 4.11235, as it matches the final values of the array arr.

Which is not a characteristics of Java programming language?

  1. 1.Robust

  2. 2.Procedural

  3. 3.Distributed

  4. 4.Multithreaded


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) Robust - This option is correct because Java programming language is known for its robustness. It includes features such as strong type checking, exception handling, and automatic memory management, which contribute to its robust nature.

Option B) Procedural - This option is incorrect because Java is not a procedural programming language. It is an object-oriented programming language that follows the principles of encapsulation, inheritance, and polymorphism.

Option C) Distributed - This option is correct because Java programming language supports distributed computing. It provides libraries and frameworks for developing distributed systems, such as Remote Method Invocation (RMI) and Java Message Service (JMS).

Option D) Multithreaded - This option is correct because Java programming language supports multithreading. It includes built-in features and libraries for creating and managing multiple threads, allowing for concurrent execution of tasks.

The correct answer is B) Procedural. This option is correct because Java is not a procedural programming language, but an object-oriented programming language.