1.
A method name min() that needs two integer arguments is declared as
Correct Answer
C. Public void min (int a, int b);
Explanation
The correct answer is "public void min (int a, int b)" because it declares a method named "min" that takes two integer arguments, "a" and "b". The "public" keyword indicates that the method can be accessed from other classes. The "void" keyword means that the method does not return any value. The method is correctly declared with the correct parameter types for two integers.
2.
You store java source code files with following extension?
Correct Answer
A. .java
Explanation
The correct answer is ".java" because Java source code files are typically saved with this extension. This allows the Java compiler to recognize and process the file as a valid Java source code file. The other options, such as ".class", ".src", and ".javadoc", are not used to store Java source code files. ".class" files are generated by the Java compiler after successfully compiling the source code, while ".src" and ".javadoc" are not standard file extensions for Java source code files.
3.
Java language has support for which following types of comments
Correct Answer
A. Block, line and javadoc
Explanation
Java language supports three types of comments: block, line, and javadoc. Block comments are enclosed between /* and */, and can span multiple lines. Line comments start with // and only cover a single line. Javadoc comments are used to generate documentation and are enclosed between /** and */. They can also span multiple lines.
4.
In Java language, the argument to the method is within
Correct Answer
B. Parenthesis
Explanation
In Java language, the argument to the method is enclosed within parentheses. Parentheses are used to define and separate the arguments that are passed to a method. This is a fundamental syntax rule in Java and is necessary for the proper execution of methods.
5.
State which of the following statements are true (1) A series of characters that appear in double quote is a Char literal(2) Java language is case sensitive(3) The Java programming language is both compiled and interpreted.(4) As long as a computer has a Java Virtual Machine, the same program written in the Java programming language can run on any computer
Correct Answer
B. 2,3 and 4
Explanation
The given answer states that statements 2, 3, and 4 are true. Statement 2 is true because Java is a case-sensitive language, meaning that uppercase and lowercase letters are considered different. Statement 3 is true because Java is both compiled and interpreted. It is compiled into bytecode and then interpreted by the Java Virtual Machine. Statement 4 is true because Java programs can run on any computer that has a Java Virtual Machine installed, regardless of the underlying hardware or operating system.
6.
What will be the result of compiling following code public class MyClass { public static void main(String args[]) { System.out.println("In first main()"); } public static void main(char args[]) { System.out.println('a'); } }
Correct Answer
C. (3) Code will compile correctly and will print "In first main()" (without quotes) when run with argument of 'a'.
Explanation
The code will compile correctly because it defines two main() methods with different parameter types. When the code is run with the argument of 'a', it will execute the main() method that accepts a char array as an argument. However, since the argument is a single character 'a', it will not match the char array parameter. Therefore, the code will not print anything.
7.
Which are the valid declarations for an integer literal (1) 0(2) -5(3) 0416(4) 0xabcdef
Correct Answer
A. All 4
Explanation
All 4 options are valid declarations for an integer literal. Option 1 represents the decimal number 0, option 2 represents the negative decimal number -5, option 3 represents the octal number 0416, and option 4 represents the hexadecimal number 0xabcdef.
8.
A subclass is also called as
Correct Answer
C. Derived class
Explanation
A subclass is also known as a derived class. In object-oriented programming, a subclass is a class that inherits properties and behaviors from a parent class (also known as a superclass). The subclass can add additional features or modify the inherited ones. Therefore, derived class is the correct term to describe a subclass.
9.
State which of the following statements are True (1) Java language support multi-dimentional arrays (2) StringBuffer class is alternative to String class (3) A class which you create only to extend from, but not to instantiatefrom is called derived class(4) You cannot instantiate objects of interfaces or abstract classes
Correct Answer
C. 1,2 and 4
Explanation
The given answer states that statements 1, 2, and 4 are true.
Statement 1 is true because Java language does support multi-dimensional arrays.
Statement 2 is true because the StringBuffer class in Java is an alternative to the String class. It provides mutable strings and additional methods for string manipulation.
Statement 4 is true because interfaces and abstract classes cannot be instantiated directly. They can only be implemented by classes or extended by other classes.
Therefore, the correct answer is 1, 2, and 4.
10.
State which of the following statements are True (1) Each method in a parent class can be overridden at most once in any one subclass(2) A method can be overloaded in the class it is defined as well as in the subclass of its class(3) Overriding methods must return exactly the same type as the method they override(4) An overriding method must not be less accessible than the method itoverrides
Correct Answer
A. All 4
Explanation
All 4 statements are true.
(1) Each method in a parent class can be overridden at most once in any one subclass, meaning that a subclass can override a method from its parent class only once.
(2) A method can be overloaded in the class it is defined as well as in the subclass of its class, meaning that a method can have multiple versions with different parameters within the same class or in its subclasses.
(3) Overriding methods must return exactly the same type as the method they override, meaning that the return type of the overriding method must be the same as the return type of the method it is overriding.
(4) An overriding method must not be less accessible than the method it overrides, meaning that the access modifier of the overriding method should be the same or more accessible than the method it is overriding.
11.
What will be the outcome of executing following code. class MyClass{ public static void main(String []args) { final int i = 100; byte b = i; System.out.println(b); }}
Correct Answer
B. Will compile and print 100
Explanation
The code will compile and print 100 because the variable "i" is declared as final, which means its value cannot be changed. When the value of "i" is assigned to the byte variable "b", it will be automatically converted to a byte value. Since the value of "i" (100) can be represented as a byte, there will be no compilation error and the value 100 will be printed.
12.
What will be the outcome of executing following code. class MyClass{ public static void main(String []args) { int i = 100; byte b = i; System.out.println(b); }}
Correct Answer
A. Will give compilation error
Explanation
The code will give a compilation error because a byte cannot directly hold the value of an integer without explicit casting. In this code, the variable "i" is of type integer and the variable "b" is of type byte. When the value of "i" is assigned to "b", there is a type mismatch because the range of a byte is smaller than the range of an integer. Therefore, the code will not compile.
13.
What will be the outcome of executing following code.class MyClass{ public static void main (String args[]) { String s1[] = new String[5]; String str = s1[0].toUpperCase(); System.out.println(str); }}
Correct Answer
B. Will give NullPointerException
Explanation
The code initializes an array of Strings, but it does not assign any values to the elements of the array. Therefore, when the code tries to access the first element of the array (s1[0]) and call the toUpperCase() method on it, a NullPointerException will occur because the element is null. This will result in a runtime error and the program will terminate.