java (2)
java (2)
1. int w = (int)888.8;
2. byte x = (byte)100L;
3. long y = (byte)100;
4. byte z = (byte)100L;
a) 1 and 2
b) 2 and 3
c) 3 and 4
d) All statements are correct
Answer - d
class average {
public static void main(String args[])
{
double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};
double result;
result = 0;
for (int i = 0; i < 6; ++i)
result = result + num[i];
System.out.print(result/6);
}
}
a) 16.34
b) 16.566666644
c) 16.46666666666667
d) 16.46666666666666
Answer - c
Answer - a
4.Which of these is an incorrect array declaration?
a) int arr[] = new int[5].
b) int [] arr = new int[5].
c) int arr[] = new int[5].
d) int arr[] = int [5] new
Answer - d
Answer - d
class increment
{
public static void main(String args[])
{
double var1 = 1 + 5;
double var2 = var1 / 4;
int var3 = 1 + 5;
int var4 = var3 / 4;
System.out.print(var2 + " " + var4);
}
}
a) 1 1
b) 0 1
c) 1.5 1
d) 1.5 1.0
Answer - c
7. Can 8 byte long data type be automatically type cast to 4 byte float data type?
a) True
b) False
Answer - a
8.Which of these keywords are used for generating an exception manually?
a) try
b) catch
c) throw
d) check
Answer - c
class Output
{
public static void main(String args[])
{
try
{
int a = 0;
int b = 5;
int c = b / a;
System.out.print("Hello");
}
}
}
a) Hello
b) World
c) HelloWOrld
d) Compilation Error
Answer: d
class exception_handling
{
public static void main(String args[])
{
try
{
throw new NullPointerException ("Hello");
System.out.print("A");
}
catch(ArithmeticException e)
{
System.out.print("B");
}
}
}
a) A
b) B
c) Compilation Error
d) Runtime Error
Answer: d
16.Which of the following methods is not used while Serialization and DeSerialization?
a) readObject()
b) readExternal()
c) readWriteObject()
d) writeObject()
Answer: c
17.Which of these is an interface for control over serialization and deserialization?
a) Serializable
b) Externalization
c) FileFilter
d) ObjectInput
Answer: b
19.Which of these methods of a Thread class is used to suspend a thread for a period of time?
a) sleep()
b) terminate()
c) suspend()
d) stop()
Answer: a
Answer: a
21.Which of these methods returns the class of an object?
a) getClass()
b) Class()
c) WhoseClass()
d) WhoseObject()
Answer : a
class Output
{
public static void main(String args[])
{
int x = 3.14;
int y = (int) Math.abs(x);
System.out.print(y);
}
}
a) 0
b) 3
c) 3.0
d) 3.1
Answer : b
27.Which of these exceptions will be thrown if we declare an array with negative size?
a) IllegalArrayException
b) IllegalArraySizeExeption
c) NegativeArrayException
d) NegativeArraySizeExeption
Answer: d
30.Which of these methods is used to retrieve the elements in properties object at specific
location?
a) get()
b) Elementat()
c) ElementAt()
d) getProperty()
Answer: d
31.What is the output of this program?
import java.util.*;
class properties
{
public static void main(String args[])
{
Properties obj = new Properties();
obj.put("AB", new Integer(3));
obj.put("BC", new Integer(2));
obj.put("CD", new Integer(8));
System.out.print(obj.keySet());
}
}
a) {AB, BC, CD}
b) [AB, BC, CD].
c) [3, 2, 8].
d) {3, 2, 8}
Answer: b
34.In order to restrict a variable of a class from inheriting to subclass, how variable should be
declared?
a) Protected
b) Private
c) Public
d) Static
Answer: b
35.If super class and subclass have same variable name, which keyword should be used to use
super class?
a) super
b) this
c) upper
d) classname
Answer: a
39.Which concept of Java is a way of converting real world objects in terms of class?
a) Polymorphism
b) Encapsulation
c) Abstraction
d) Inheritance
Answer: c
40.What is it called if an object has its own lifecycle and there is no owner?
a) Aggregation
b) Composition
c) Encapsulation
d) Association
Answer: d