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

java3

The document consists of a series of multiple-choice questions related to Java programming concepts, covering topics such as constructors, garbage collection, inheritance, interfaces, packages, and exception handling. Each question is followed by options labeled with letters indicating the correct answer. The content serves as a quiz or study material for individuals looking to test their knowledge of Java programming.

Uploaded by

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

java3

The document consists of a series of multiple-choice questions related to Java programming concepts, covering topics such as constructors, garbage collection, inheritance, interfaces, packages, and exception handling. Each question is followed by options labeled with letters indicating the correct answer. The content serves as a quiz or study material for individuals looking to test their knowledge of Java programming.

Uploaded by

Praveen Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

1) A Java constructor is like a method without B

a) statements
b) return type
c) argument list
d) None

2) The name of a constructor and the name of a class are A


a) Same
b) Different
c) -
d) –
3) The placement of a constructor inside a class should be . C
a) Always at the beginning of class

b) Always at the end of class

c) Anywhere in the class

d) None

4) Memory is allocated to an object once the execution of is over in Java


language.
a) main method
b) constructor
c) destructor
d) None

5) In Java, a constructor with no parameters or no arguments is called


Constructor . A
a) Default constructor
b) User-defined constructor
c) -
d) –
6) In Java, a constructor with one or more arguments or parameters is called a
constructor. B
a) Default constructor
b) User-defined constructor or Non-default constructor
c) -
d) -
7. Which function isused to perform some action when the object is to be
A destroyed?
a) finalize()
b) delete()
c) main()
d) none of the mentioned

8. Garbage Collection can be controlled by a program? B


a) True

b) False
9. What is true of the finalize() method? A
a) It may be called zero or one times.
b) It may be called zero or more times.
c) It will be called exactly once.
d) It may be called one or more times.

10. Which of these cannot be declared static? B


a) class
b) object
c) variable
d) method

11. Which of these methods must be made static? A


a) main()
b) delete()
c) run()
d) finalize()

12. Can the Java program accept input from the command line?
A
a) Yes, using command-line arguments
b) Yes, by access command-prompt
c) No
d) None of these
13. this' keyword in java is . A
a) Used to hold the reference of the current object
b) Holds object value
c) Used to create a new instance
d) All of these
14.The 'super' keyword is used to . A

a) Access instance of the parent class


b) Access instance of the same class
c) Access instance of child class
d) Access instance of friend class
15)The super() method is used to ------. C
a) Call constructor of friend class
b) Is a declared method
c) Call constructor of the parent class
d) Call constructor

16)A command-line argument in java is a value passed at the time of ---- a


program. B
a) Compiling
b) Running
c) –
d) –

17)The command-line arguments are passed at-----. B


a) Runtime
b) The time of executing a java program
c) The time of compiling a java program
d) None

18)Which is the method that accepts data passed in the form of command-line
arguments in Java? B
a) Show() method
b) Main() method
c) Display() method
d) Print() method

19.The data that is passed at the time of running a Java program as command-
line arguments are converted into _____datatype. D

a) Integer array
b) Float array
c) Character array
d) String array

20.Which are the methods used to parse string values to the respective data
types in java. D

a) Boolean.parseBoolean(), Byte.parseByte()
b) Integer.parseInt(),Long.parseLong()
c) Float.parseFloat(), Double.parseDouble()
d) All the above

21. A nested class can have its own static members. B


a) True
b) False
22.Which of the following is true about anonymous inner classes? D
a) You can create ‘n’ number of objects to anonymous inner classes.
b) Anonymous inner classes will not have the name.
c) You can instantiate anonymous inner classes only once.
d) b and c

23.Super keyword in java is used to D


a) Refer immediate parent class instance variables.
b) Invoke immediate parent class methods.
c) Invoke immediate parent class constructor.
d) Al

24.What would be the behaviour if this() and super() used in a method? C


a) Runtime error
b) Throws exception
c) compile time error
d) Runs successfully
25.What is not the use of “this” keyword in Java? D
a) Passing itself to another method
b) Calling another constructor in constructor chaining
c) Referring to the instance variable when local variable has the same name
d) Passing itself to method of the same class

26.Which of the following can be declared as final in java? D


a) Class
b) Method
c) Variable
d) All of these
27.Abstract class is . D
a) Created using abstract keyword
b) Contains only abstract method
c) Needs to be inherited to be used
d) All of these
28.Which of these is true for interfaces in java? D
a) The keyword interface is used to create a method
b) All the methods of an interface are abstract
c) It does not contain constructors
d) All of these
29.Which keyword is used to inherit classes in Java? A
a) extends
b) inheritance
c) isChild
d) None of these
30. Which of the following inheritance of class is invalid in Java? B
a) Single
b) Multiple
c) Multi-level
d) Hierarchical
31. What is a subclass in Java inheritance? A
a) The class that inherits from another class
b) The class that is inherited from
c) The final class in the inheritance chain
d) None of the above

32. Can we perform multiple inheritance in Java? B


a)YES

b) No

33. A class which is declared with the keyword is known as


an abstract class in Java.
A

a) abstract
b) util
c) extends
d) None of the above

34. Abstract class can have constructors and static methods? A

a) TRUE
b) FALSE
c) Abstract class can have constructors but can-not have static methods.
d) Abstract class can-not have constructors but can have static methods.
36.An abstract class in Java usually contains one or more abstract _________. B
a) constructors

b) methods

c) variables

d) None
37.Just like an Interface, you can define constants in abstract classes in Java
State TRUE or FALSE
A
a) TRUE
b) FALSE

c) -

d) –

38.Abstract classes support __inheritance. B

a) Multiple

b) Multilevel

c) Hierarchal

d) Single

39.What is method overriding in Java?


D
a) Writing a method in a sub class with the same name of superclass's method

b) Mentioning the same return type of the method of the superclass

c) The argument-list in the method of sub-class and the method of super-class should be the same

d) All the above

40.The Method-Overloading and Method-Overriding are not the same. State


TRUE or FALSE. A
a) TRUE

b) FALSE

c) -

d) -
41.A successful Method-Overriding calls the method of _in Java. B
a) Superclass

b) Subclass

c) -

d) –

42.If the method signature of a Superclass and the method signature of a


Sub-class are the same, then the sub-class method is said to be ___the
super-class's method. A

a) Overriding
b) Overloading
c) -
d) -

43. Which of these keywords is used to define interfaces in Java? A


a) interface
b) Interface
c) intf
d) Intf

44. Which of these keywords is used by a class to use an interface


defined previously? C
a) Import
b) import
c) implements
d) Implements

45. Which is the correct way to inherit and implement the interface? A

a) classCatimplementsIAnimal{}
b) classCatimportIAnimal{}
c) classCatextendsIAnimal{}
d) Noneiscorrect
46. which of the following is true about methods in an interface in java? A

a) An interface can contain only abstract method.


b) We can define a method in an interface
c) Private and protected access-modifiers can also be used to declare methods in
interface
d) None of the above

47. Which of these can be used to fully abstract a class from


its implementation? C

A. Objects
B. Packages
C. Interfaces
D. NoneoftheMentioned

48. All methods must be implemented of an interface. A

A. TRUE
B. FALSE
C. Canbetrueor false
D. cannotsay

49. What type of methods an interface contains by default? A

A. abstract
B. static
C. final
D. private

50. can be defined as the process where one class


acquires the properties (methods and fields) of another.
B

A. Overriding
B. Inheritance
C. Polymorphism
D. Abstraction
51. Subclass also known as ? D

A. Derived class
B. Child class
C. Base class
D. Both A and B

52. What are packages in Java?


C

A. Methods of a friend-class
B. Methods of the main-class
C. Way to encapsulate a group of classes, sub-packages, and interface
D. All of these

53. Package in Java is a mechanism to encapsulate a . D

A. Classes
B. Sub Packages
C. Interfaces
D. All of the above

54. Which of these keywords is used to define packages in Java?


C

A. pkg
B. Pkg
C. package
D. Package

55. Package names and directory structure are closely related. A

A. TRUE
B. FALSE
C. Can be true or false
D. Can-not say
56. Which of the following packages is used to includes utility classes
like Calendar, Collection, Date? D
A. java.lang
B. java.net
C. java.awt
D. java.util

57. Which of the following is the correct way of importing an


entire package "pkg"? C

A. importpkg.
B. Importpkg.
C. importpkg.*
D. Importpkg.*

58. Packages that are inside another package are the ___. D

A. packages
B. nested packages
C. util sub packages
D. sub packages

59. Which of these classes is not included in java.lang? C

A. Class
B. Integer
C. Array
D. Byte

60. Standard output variable "out" is defined in which class? D

A. Void
B. Process
C. Runtime
D. System

61.Which of the following packages to recall the standard java classes? B


a) lang

b) java
c) util
62.If you import a package, subpackages will not be imported? A

A) True

B) False

63.Which package is used for GUI?B

A) java.lang

B) java.awt

C) java.lang.ref

D) java.io

64.In which all standard classes of java are included with in a package is ?A

A) java.lang

B) java.math

C) java.ref

D) java.util

65.Which is used to separate the hierarchy of the class while declaring an


import statement? A

A) Package

B) Applet

C) Browser

D) Both A &B

66. Can a class belong to multiple packages simultaneously? B

A) Yes, but it requires advanced import statements.


B) No, a class can belong to only one package.
C) Yes, but it causes naming conflicts.
D)Yes, if it’s placed in the default package.
67. What’s the purpose of the CLASSPATH environment-variable? C

A) It sets the default package for a project.

B) It defines the location of Java compiler.

C) It specifies where to find compiled classes and packages.

D)It issued for creating class documentation.

68. If you have classes-A and Bin package my-Package, which import
statement is correct to use them in another class? B

A) Import my-Package.*;
B) import my-Package.A,B;
C) import A,B from my-Package;
D)import class my-Package. A, my-Package. B;
69. Can two classes with the same name exist in different packages? B

A) No, class names must be unique across all packages.


B) Yes, but they must have distinct method names.
C) Yes, but it leads to naming conflicts.
D)No, Java enforces unique class names globally.
70. What does the import statement do? A

A) Includes package contents


B) Creates objects
C) Imports all classes
D)Defines new packages
71.What are the types of Inheritances (Whether Java supports or not)
available in Object-Oriented Programming Languages? D
a) Single-Inheritance

b) Multi-Level Inheritance, Hierarchical Inheritance

c) Multiple-Inheritance, Hybrid-Inheritance

d) All the above

72.In a Single-inheritance, Class B inherits only from Class A. State TRUE or


FALSE. A
a) True

b) False
73.In a Multi-Level Inheritance Class-C inherits from Class-B and Class-B
inherits from Class-A. State TRUE or FALSE. A
a) TRUE
b) FALSE

74.When a Class inherits two super classes (not in Java), it is called


inheritance. B
a) Multilevel inheritance
b) Single Inheritance
c) Multiple Inheritance
d) None

75.Choose the correct syntax of a Java Package below. A


a) package PACKAGE_NAME;
b) package PACKAGE_NAME.*;
c) pkg PACKAGE_NAME;
d) pkg PACKAGE_NAME.*;

76.What is an Exception in Java? D


a) An exception is like a generic error occurring during the time of execution of program
b) An exception may occur due to memory or hardware issues
c) An exception leads to bad experience for an End user of the software
d) All the above

77.Are the classes Error and Exception similar in Java? A

a) No
b) YES
c) -
d) -

78.Which is the super class in Java that bundles all classes to deal with
exceptions and errors? C

a) Error
b) Exception
c) Throwable
d) Throw
79.Which are the keywords used to handle exceptions in Java? D
a) TRY, CATCH
b) FINALLY
c) THROW, THROWS
d) All the above
80.Where should you keep your Java code for checking against runtime
exceptions? A

a) Inside TRY block


b) Inside CATCH block
c) Inside FINALLY block
81.Where should you keep your Java code that helps to take action on the
exceptions raised inside TRY block? B

a) One more TRY block


b) CATCH block
c) FINALLY block
d) None of the above
82.Java exceptions are handled by ___. B

a) Java Compiler
b) Java Runtime
c) –
83.Can you add more than one CATCH block when handling exceptions in Java?

a) NO
b) Yes
c) –
84.Where do you keep the Java code that should be executed at all times even
if an exception occurs? C

a) Inside TRY block


b) Inside CATCH block
c) Inside FINALLY block
d) All the above

85.Choose the correct way of writing TRY CATCH FINALLY blocks in Java. D
a) try{}
catch{}
finally{}
b) try{}finally{}
c) try{}catch{}
d) All the above
86.The FINALLY block should always be accompanied by a __block in Java. A
a) TRY
b) CATCH
c) FINALLY
d) None
87.Can you catch an object of type Error in Java using TRY-CATCH blocks? A

a) Yes
a) No
b) -
c) –
88.Which is the super class of Error class in Java? C
a) RuntimeException
b) Exception
c) Throwable
d) Noneofthe above

89.Who closes there sources using code in a TRY-with-resources


block in Java? A
a) Compiler
b) Runtime
c) Programmer
d) None

90. Which of these key-words must be used to monitor for exceptions?


A
a) try
b) finally
c) throw
d) catch

91. Which of these statements is incorrect?


D
a. Try block need not to be followed by catch block
b. Try block can be followed by finally block instead of catch block
c. Try can be followed by both catch and finally block
d. Try need not to be followed by anything

92. Which of these exceptions handles the divide by zero error?


A
a) Arithmetic Exception

b) Math Exception

c) Illegal Access Exception

d) Illegal Exception

93. What requires less resources? A


a) Thread
b) Process
c) Thread and Process
d) Neither Thread nor Process

94. Which of the following is a correct constructor for thread? A

a) Thread(Runnable, String str)

b) Thread(int priority)

c) Thread(Runnable a , int priority)

d) Thread(Runnable a , Thread Group t)

95.Which of the following will ensure the thread will be in running state? C
a) yield()

b) notify()

c) wait()

d) Thread.killThread()
96. Which of this method is used to tell the calling thread to give up a
monitor and go to sleep until some other thread enters the same monitor? A

a) wait()
b) notify()
c) notifyAll()
d) sleep()

97. The life cycle of a thread in java is controlled by C


a) JRE
b) JDK
c) JVM
d) None

98. Which of this method of Thread class is used to find out the
priority given to a thread?
C

a) get()
b) ThreadPriority()
c) getPriority()
d) getThreadPriority()

99) Which of this method of Thread class is used to Suspend a thread for a
period of time? A
a) sleep()
b) terminate()
c) suspend()
d) stop()

100) In Which state after invocation of start()method, but the thread


Scheduler has not selected it to be the running thread? B
a) Running
b) Runnable
c) Terminated
d) Non-Runnable

101)These two ways are used to ? C


By extending Thread class
By implementing Runnable interface
a) Joining a thread
b) Naming a thread
c) Create a thread
d) Sleeping a thread

102) Thread class constructor allocates a new thread object? A


a) True
b) False

103) How many methods does a thread class provides for sleeping a thread?
D
a) 3
b) 1
c) 4
d) 2

104)Can we start a thread? B


a) Yes
b) No

105) Which method returns a reference to the currently executing thread


object? A
a) currentThread()

b) runningThread()

c) runnableThread()

d) None of the above

106) What is the name of the method used to start a thread execution?
C
a) run();

b) init();

c) start();

d) resume();

107) Which will contain the body of the thread?


a) main();
b)stop();
c) start();
d)run();

108) What is multithreaded programming? C


a) It is a process in which two different processes run simultaneously
b)It’s a process in which a single process can access information from many sources
c) It is a process in which two or more parts of same process run
d)It is a process in which many different process are able to access same information

109) Thread priority in Java is? A


a) Integer
b)Float
c) Double
d)Long

110)What requires less resources? A


a) Thread

b) Process

c) Thread and Process

d) Neither Thread nor Process

111) Which of these functions is called to display the output of an applet?


B
a) display()

b) paint()

c) displayApplet()

d) printApplet()

112) Which of these methods is a part of Abstract Window Toolkit(AWT)?


B
a) display()

b) paint()

c) drawString()

d) transient()

113) Which of these methods can be used to output a string in an applet?


C
a) display()

b) print()
c) drwaString()

d) transient()

114)An applet is a Java class that extends the? D


a) java.Applet class

b) java class

c) Applet class

d) Java.applet.Applet class

115) Applets are designed to be embedded within an-------. C


a) Javascript

b) CSS

c) Html

d) SQL

116) Which of the following is required to view an applet? C


a)JCM
b)JDM
c) JV<
d)Java class

117) paint() is an abstract method defined in AWT. A


a)TRUE
b)FALSE
c) Can be true or false
d)Can not say

118)What does AWT stands for ? C


a)All window tools
b)All writing tools
c) Abstract window toolkit
d)Abstract writing toolkit

119)When an applet is terminated which of the following sequence of


methods calls take place? D
a) stop(), paint(), destroy()
b) destroy(), stop(), paint()
c) destroy(), stop()
d) stop(), destroy()
120)All Applets must import java.applet an java.awt A
a) True

b) False

121)The ------class is an abstract class that represents the display area of the
applet. B
a) Display

b) Graphics

c) Text

d) Are

122)All Applets are subclass of Applet. A


a) True

b) False

123)The-------- method called the first time an applet is loaded into the memory
of a computer. A
a) Init()

b) Start()

c) Stop()

d) Destroy()

124)An Applet is a----------- of panel. A


a) Subclass

b) Superclass

c) Both a and b

d) None of these

125)Which method is automatically called after the browser calls the init
method? A
a) Start
b) Stop

c) Destroy

d) Paint

You might also like