0% found this document useful (0 votes)
3 views

java (2)

The document contains a practice exam for Core Java, featuring multiple-choice questions covering various Java concepts such as data types, exception handling, serialization, and object-oriented programming principles. Each question includes options and the correct answer is provided at the end of each item. The exam is designed to test knowledge and understanding of Java programming fundamentals.

Uploaded by

adef17354
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

java (2)

The document contains a practice exam for Core Java, featuring multiple-choice questions covering various Java concepts such as data types, exception handling, serialization, and object-oriented programming principles. Each question includes options and the correct answer is provided at the end of each item. The exam is designed to test knowledge and understanding of Java programming fundamentals.

Uploaded by

adef17354
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Core_Java_CCEE_Practice

C-DAC Kharghar/Aug_2018 Exam Time : 60 min

1.Which of the following are legal lines of Java code?

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

2.What is the output of this program?

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

3.What is Truncation is Java?


a) Floating-point value assigned to an integer type
b) Integer value assigned to floating type
c) Floating-point value assigned to an Floating type
d) Integer value assigned to floating type

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

5. What will this code print?

int arr[] = new int [5];


System.out.print(arr);
a) 0
b) value stored in arr[0].
c) 00000
d) Class name@ hashcode in hexadecimal form

Answer - d

6.What is the output of this program?

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

9.What is the output of this program?

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

10.Which of these methods is used to print stack trace?


a) obtainStackTrace()
b) printStackTrace()
c) getStackTrace()
d) displayStackTrace()
Answer: b

11.Which of these classes is super class of Exception class?


a) Throwable
b) System
c) RunTime
d) Class
Answer: a
12. What is the output of this program?

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

13.​Which of these class extend InputStream class?


a) ObjectStream
b) ObjectInputStream
c) ObjectOutput
d) ObjectInput
Answer: b

14.How many methods Serializable has?


a) 1
b) 2
c) 3
d) 0
Answer: d

15.Default Serialization process cannot be overridden.


a) True
b) False
Answer: b

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

18. How to use environment properties in the class?


a) @Autowired
b) @Variable
c) @Property
d) @Environment
Answer: a

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

20.What is the output of this program?

class newthread implements Runnable


{
Thread t;
newthread()
{
t = new Thread(this,"My Thread");
t.start();
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
a) My Thread
b) Thread[My Thread,5,main].
c) Compilation Error
d) Runtime Error

Answer: a
21.Which of these methods returns the class of an object?
a) getClass()
b) Class()
c) WhoseClass()
d) WhoseObject()
Answer : a

22.Which of these class is a superclass of all other classes?


a) Math
b) Process
c) System
d) Object
Answer : d

23.What is the output of this program?

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

24.Which of these method can set the out stream to OutputStream?


a) setStream()
b) setosteam()
c) setOut()
d) streamtoOstream()
Answer: c

25. Which of these class is not a member class of java.io package?


a) String
b) StringReader
c) Writer
d) File
Answer: a
26.Which of these interface is not a member of java.io package?
a) DataInput
b) ObjectInput
c) ObjectFilter
d) FileFilter
Answer: c

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

28. Which of these class is used to create user defined exception?


a) java.lang
b) Exception
c) RunTime
d) System
Answer: b

29.Which of these is the interface of legacy is implemented by Hashtable and Dictionary


classes?
a) Map
b) Enumeration
c) HashMap
d) Hashtable
Answer: a

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

32.​.​ Which of these packages contain all the collection classes?


a) java.util
b)java.lang
c) java.net
d) java.awt
Answer: a

33.What is Collection in Java?


a) A group of objects
b) A group of classes
c) A group of interfaces
d) None of the mentioned
Answer: a

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

36Static members are not inherited to subclass.


a) True
b) False
Answer: b

37.Which of the following is used for implementing inheritance through class?


a) inherited
b) using
c) extends
d) implements
Answer: c

38.What is use of interpreter?


a) They read high level code and execute them
b) They convert bytecode to machine language code
c) They are intermediate between JIT and JVM
d) It is a synonym for JIT
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

You might also like