Sunteți pe pagina 1din 32

Что такое приведение типов? Какие приведения типов Вы знаете? В чем их отличие?

Какие вы знаете правила преобразования типов при выполнении операций?


Для чего используются операторы break и continue? В чем их различие?
Question How many objects will be created in the following code and where they will
be stored?

String str1 = new String("Tech");


String str2 = new String("Beamers");

1. None of these.
2. Two objects will be created and they will be stored in the stack.
3. Four objects will be created and they will be stored in the heap memory.
4. Two objects will be created and they will be stored in the heap memory.
Question Can an abstract superclass have non-abstract subclasses?
1. No – an abstract superclass may only have abstract subclasses.
2. No – an abstract superclass may not have a subclass at all.
3. Yes, all subclasses of an abstract superclass do not have to be abstract.
4. Yes – an abstract superclass can have both abstract and non-abstract subclasses.
Question Can an abstract method be defined in a non-abstract class?
1. No – if a class defines an abstract method, the class itself must be abstract.
2. No – only classes are abstract, not methods.
3. Yes, a method can be declared abstract in any superclass, as long as it also declares the
subclasses to be abstract.
4. Yes – there are no restrictions where abstract methods can be defined.
Question Which statement is valid for the fact mentioned below?
Immutable objects are naturally thread-safe.
1. None of these.
2. true
3. false
Question Which of the following is the correct difference between String and
StringBuffer in Java?
1. String is immutable, you can use StringBuffer whenever you need to modify a String.
2. String is handled very efficiently in terms of memory and execution time by most
jvm's while StringBuffer is not.
3. String and StringBuffer are two different classes they are used in context of
concatenating two Strings.
4. None of these.
Question What is the result of the below lines of code?

public class TestStrings {


public static void main(String params[]){
String StrArr[]={"JAVA","JDK","JRE"};
String Str="JAVA";
System.out.println(StrArr[0]==Str);
}
}
1. false
2. Runtime error
3. Compile time error
4. true
Question Which of the following correctly defines the toString() method in Java?
1. None of these.
2. The toString() method returns the byte representation of String object.
3. The toString() method convert an object into string.
4. The toString() method returns the string representation of any object.
Question Which of the following is a difference between StringBuffer and StringBuilder
class?

1. None of these.
2. StringBuffer and StringBuilder class both produces mutable string objects.
3. StringBuffer produces mutable string objects while StringBuilder does not.
4. StringBuffer class is thread safe whereas StringBuilder class is not thread safe.
Question What is the result of the below lines of code?
class MyNum {
int i;
int j;
void A() {
i = 1;
j = 2; }
}
class MyStr {
public static void main(String args[]) {
MyNum testObj = new MyNum();
System.out.print(testObj.toString());
}}

1. String associated with testObj


2. false
3. Compile time error
4. true
Question Which of the following correctly describes the difference in the way the two
“==” and equals() work in Java?
1. None of these.
2. "==" is an operator while equals" is a method.
3. "==" tests if two objects refer to the same memory location while the equals()
method verifies if two distinct objects can still be equal.
4. "==" tests whether two references point to the same object while the equals()
method compares the object state.
Question Which of these keywords is used by the calling function to guard against the
exception that is thrown by called function?
1. try
2. throw
3. throws
4. catch
5. None of these.
Question What is the output of the following Java code?
class exception_handling {
public static void main(String args[]) {
try {
int a, b;
b = 0;
a = 5 / b;
System.out.print("A");
} catch(ArithmeticException e) {
System.out.print("B");
}
} }

1. B
2. A
3. Runtime Error
4. None of these.
5. Compilation Error
Question Which of these methods return description of an exception?

1. getMessage()
2. obtainDescription()
3. obtainException()
4. getException()
5. None of these.
Question What is the output of this Java code fragment?
class exception_handling {
public static void main(String args[]) {
try {
int a, b;
b = 0;
a = 5 / b;
System.out.print("A");
} catch(ArithmeticException e) {
System.out.print("B");
} finally {
System.out.print("C");
}
} }

1. A
2. BC
3. B
4. AC
Question Which of these methods is used to print stack trace?
1. displayStackTrace()
2. obtainStackTrace()
3. printStackTrace()
4. getStackTrace()
Question Which of these keywords is used to manually throw an exception?
1. finally
2. try
3. None of these.
4. throw
5. catch
Question Why are generics used?

1. Generics make code more fast


2. Generics add stability to your code by making more of your bugs detectable at compile
time
3. Generics make code more optimised and readable
4. Generics add stability to your code by making more of your bugs detectable at run time
Question Which of these type parameters is used for a generic class to return and
accept any type of object?

1. T
2. V
3. K
4. G
Question What Is a Bounded Type Parameter?

(ограничения обобщений)
Question Which of the following reference types cannot be generic?

1. Interface
2. All of the mentioned
3. Inner class
4. Anonymous inner class
Question What are generic methods?

1. Generic methods are methods that introduce their own type parameters
2. Generic methods are the methods defined in a generic class
3. Generic methods are methods that take void parameters
4. Generic methods are the methods that extend generic class’s methods
Question Which of these types cannot be used to initiate a generic type?

1. Collections
2. Integer class
3. Float class
4. Primitive Types
Question Which of these instance cannot be created?

1. Generic class instance


2. Generic type instance
3. Collection instances
4. Integer instance
Question Which of the following cannot be Type parameterized?

1. Class methods
2. Overriding methods
3. Generic methods
4. Oveloaded Methods
Question Which of these is wildcard symbol?

1. !
2. %
3. &
4. ?
Question What is use of wildcards?

1. It is used in cases when type being operated upon is not known


2. It is used to access members of super class
3. It is used to make code more readable
4. It is used for type argument of generic method

S-ar putea să vă placă și