1. What is stored in the object object in the following lines of Java code?
Box obj;
A) Memory address of the allocated memory of the object
b) NULL
C) any arbitrary indicator
d)Garbage
Answer: B
Explanation: Memory is allocated to an object using the new operator. Box obj; Just declares a reference to the object, no memory is allocated for it, so it points to NULL.
2. Which of these keywords is used to create a class?
A Class
b) structure
c) int
d) none of the mentioned
Answer: A
Explanation: None.
3. Which of the following classes is a valid declaration of an object in a box?
a) box obj = new Box ();
B) box obj = new box;
c) obj = new box ();
D) new box obj;
Answer: A
Explanation: None.
4. Which of these operators is used to allocate memory for an object?
a) Malock
b) allotted
C) new
d) give
Answer: C
Explanation: The operator new dynamically allocates memory for an object and references it. This reference is in memory of the object allocated by the new.
5. Which of the following statements is incorrect?
a) Every class must have a main () method
B) apple does not require a main () method
C) A program can have only one main () method.
d) The main () method should be made public
Answer: A
Explanation: Each class does not require a main () method, there can only be one main () method that is made public.
7. Which of the following statements is correct?
A) The public system is accessible to all other classes in the hierarchy
b) Public law is accessible only to subclasses of its parent class
c) The public method can only be called by the object of its class
d) The public method can be accessed by calling the object of the public class
Answer: A
Explanation: None.
8. What will be the output of the following Java program?
Class box
{
Int width;
Int height;
Length of int;
}
Class manclass
{
public static void main (String [] args[])
{
box obj = new box ();
obj.width = 10;
obj.height = 2;
obj.length = 10;
int y = obj.width * obj.height * obj.length;
System.out.print (y);
}
}
a) 12
b) Rs 200
c) 400
d) 100
Answer: B
Explanation: None.
Output: $ javac mainclass.java $ java mainclass 200
9. What will be the output of the following Java program?
Class box
{
Int width;
Int height;
Length of int;
}
Class manclass
{
public static void main (String [] args[])
{
Box obj1 = new box ();
Box obj2 = new box ();
obj1.height = 1;
obj1.length = 2;
obj1.width = 1;
obj2 = obj1;
Println (obj2.height);
}
}
A) 1
b) 2
C) runtime error
D) waste value
Answer: A
Explanation: When we assign an object to another object of the same type, all elements of the right-hand side are copied to the operator of the =, equal to the object on the left.
Output: $ javac mainclass.java $ java mainclass 1
10. What will be the output of the following Java program?
Class box
{
Int width;
Int height;
Length of int;
}
Class manclass
{
public static void main (String [] args[])
{
box obj = new box ();
Println (obj);
}
}
A) 0
B) 1
C) runtime error
D) classname @hashcode in hexadecimal form
Answer: D
Explanation: When we print toString () internally, it will be asked to return the string in this format classname @ hashcode in hexadecimal form.
Output: $ javac mainclass.java $ java mainclass box @ 130671e
11. What is the return type of a method that returns no value?
a) int
B) float
C) zero
D) double
Answer: C
Explanation: If no value is returning, some type of return method must be made null.
12. What is the procedure for defining more than one method in a class differentiated by method signature?
A) overriding function
B) function overloading
c) function doubling
d) none of the mentioned
Answer: B
Explanation: Function overloading is a process of defining more than one method in a class, which has the same name that is separated from the function signature i: e return type or parameter type and number. Example - int quantity (int length, int width) and int segment (int length, int width, int height) can be used to calculate a quantity.
13. Which of the following is a method whose name is similar to that of the same class?
a) finalize
b) delete
C) class
d) Constructor
Answer: D
Explanation: A construction is a method that starts an object immediately upon creation. Its name is similar to the class in which it resides.
14. Which method can be defined only once in a program?
a) main method
B) final method
C) static method
D) Private Law
Answer: A
Explanation: The main () method can be defined only once in a program. The execution of the program starts with the main () method by the Java runtime system.