java interview que.docx

22
Java Interview Questions and Answers are given below Questions 1.The Java interpreter is used for the execution of the source code. a)True b) False Answers : a. Questions 2) On successful compilation a file with the class extension is cre ated. a)True b) False Answers : a. Questions 3) The Java source code can be created in a Notepad editor. a)True b) False Answers : a. Questions ) The Java !ro"ram is enclosed in a class definition. a)True b) False Answers : a. Questions #) $hat declarations are re%uired for ever& Java application' Answers : ( class and the main ) method declarations. Questions *) $hat are the two parts in executin" a Java pro"ram and their purposes' Answers : Two parts in executin" a Java pro"ram are+ Java ,ompiler and Java -nterpreter. The Java ,ompiler is used for compilation and the Java -nterpreter is used for execution of the application. Questions) $hat are the three OO!s principles and define them' Answers : /ncapsulation0 -nheritance and !ol&morphism are the three OO!s !rinciples. Encapsulation: -s the echanism that binds to"ether code and the data it manipulates0 and eeps both safe from outside interference and misuse. Inheritance: -s the process b& which one obect ac %uires the properties of another obect. Polymorphism: -s a feature that allows one interface to be used for a "eneral class of actions. Questions 4) $hat is a compilation unit' Answers : Java source code file. Questions5) $hat output is displa&ed as the result of executin" the followin" statement' 6&stem.out.println788 9oos lie a comment.7):  88 9oos lie a comment The statement results in a compilation error 9oos lie a comment No output is displa&ed Answers : a. Questions 1;) -n order for a source code file0 containin" the public class Test0 to successfull& compile0 which of the followin" must be true' -t must have a paca"e statement -t must be named Te st.ava -t must import ava.lan" -t must declare a public class named Test Answers : b Questions 11) $hat are identifiers and what is namin" convention' Answers : -dentifiers are used for class names0 method names and variable names. (n identifier ma& be an& descriptive se%uence of upper case < lower c ase letters0numbers or underscore or dollar si"n and must not be"in with numbers.

Upload: rishikesh

Post on 01-Jun-2018

232 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 1/22

Java Interview Questions and Answers are given belowQuestions 1.The Java interpreter is used for the execution of the source code.a)True b) False

Answers : a.

Questions 2) On successful compilation a file with the class extension is created.a)True b) False

Answers : a.Questions 3) The Java source code can be created in a Notepad editor.a)True b) False

Answers : a.Questions ) The Java !ro"ram is enclosed in a class definition.

a)True b) FalseAnswers : a.

Questions #) $hat declarations are re%uired for ever& Java application'Answers : ( class and the main ) method declarations.

Questions *) $hat are the two parts in executin" a Java pro"ram and their purposes'Answers : Two parts in executin" a Java pro"ram are+

Java ,ompiler and Java -nterpreter.

The Java ,ompiler is used for compilation and the Java -nterpreter is used for execution ofthe application.Questions) $hat are the three OO!s principles and define them'

Answers : /ncapsulation0 -nheritance and !ol&morphism are the three OO!s!rinciples.

Encapsulation:-s the echanism that binds to"ether code and the data it manipulates0 and eeps both safe

from outside interference and misuse.

Inheritance:-s the process b& which one obect ac%uires the properties of another obect.

Polymorphism:-s a feature that allows one interface to be used for a "eneral class of actions.

Questions 4) $hat is a compilation unit'

Answers : Java source code file.

Questions5) $hat output is displa&ed as the result of executin" the followin" statement'

6&stem.out.println788 9oos lie a comment.7): 88 9oos lie a comment

The statement results in a compilation error9oos lie a comment

No output is displa&edAnswers : a.

Questions 1;) -n order for a source code file0 containin" the public class Test0 tosuccessfull& compile0 which of the followin" must be true'

-t must have a paca"e statement-t must be named Test.ava

-t must import ava.lan"-t must declare a public class named Test

Answers : b

Questions 11) $hat are identifiers and what is namin" convention'

Answers : -dentifiers are used for class names0 method names and variable names. (nidentifier ma& be an& descriptive se%uence of upper case < lower case letters0numbers or

underscore or dollar si"n and must not be"in with numbers.

Page 2: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 2/22

Questions 12) $hat is the return t&pe of pro"ram=s main ) method'Answers : void

Questions 13) $hat is the ar"ument t&pe of pro"ram=s main ) method'Answers : strin" arra&.

Questions 1) $hich characters are as first characters of an identifier'Answers : ( > ?0 a > @0 A 0B

Questions 1#) $hat are different comments'Answers : 1) 88 CC sin"le line comment

2) 8D CCD8 multiple line comment

3) 8DD CCD8 documentation

Questions 1*) $hat is the difference between constructor method and method'

Answers : ,onstructor will be automaticall& invoed when an obect is created. $hereas

method has to be call explicitl&.

Questions 1) what is the use of bin and lib in JE'

Answers : Gin contains all tools such as avac0 applet viewer0 awt tool etc.0 whereas 9ib

contains all paca"es and variables.

Java Data types, variables and Arrays questions with

answersH Questions 1) $hat is meant b& variable'

Answers : Iariables are locations in memor& that can hold values. Gefore assi"nin" an&

value to a variable0 it must be declared.

Questions 2) $hat are the inds of variables in Java' $hat are their uses'

Answers : Java has three inds of variables namel&0 the instance variable0 the localvariable and the class variable.9ocal variables are used inside blocs as counters or in methods as temporar& variables and

are used to store information needed b& a sin"le method.

-nstance variables are used to define attributes or the state of a particular obect and areused to store information needed b& multiple methods in the obects.

,lass variables are "lobal to a class and to all the instances of the class and are useful forcommunicatin" between different obects of all the same class or eepin" trac of "lobal

states.Questions3) ow are the variables declared'

Answers : Iariables can be declared an&where in the method definition and can beinitiali@ed durin" their declaration.The& are commonl& declared before usa"e at the

be"innin" of the definition.Iariables with the same data t&pe can be declared to"ether. 9ocal variables must be "iven a

value before usa"e.Questions ) $hat are variable t&pes'

Answers : Iariable t&pes can be an& data t&pe that ava supports0 which includes the ei"ht

primitive data t&pes0 the name of a class or interface and an arra&.Questions #) ow do &ou assi"n values to variables'

Answers : Ialues are assi"ned to variables usin" the assi"nment operator K.

Questions *) $hat is a literal' ow man& t&pes of literals are there'

Answers : ( literal represents a value of a certain t&pe where the t&pe describes how that

value behaves.There are different t&pes of literals namel& number literals0 character literals0

boolean literals0 strin" literals0etc.

Questions ) $hat is an arra&'

Page 3: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 3/22

Answers : (n arra& is an obect that stores a list of items.Questions 4) ow do &ou declare an arra&'

Answers : (rra& variable indicates the t&pe of obect that the arra& holds./x+ int arrLM:

Questions 5) Java supports multidimensional arra&s.a)True

b)FalseAnswers : a.

Questions 1;) (n arra& of arra&s can be created.a)True

b)False

Answers : a.

Questions 11) $hat is a strin"'

Answers : ( combination of characters is called as strin".

Questions12) 6trin"s are instances of the class 6trin".a)True

b)False

Answers : a.

Questions 13) $hen a strin" literal is used in the pro"ram0 Java automaticall& creates

instances of the strin" class.a)Trueb)False

Answers : a.Questions 1) $hich operator is to create and concatenate strin"'

Answers : (ddition operator).Questions1#) $hich of the followin" declare an arra& of strin" obects'

6trin"L M s:6trin" L Ms+

6trin"L sM+6trin" sL M+

Answers : a0 b and d

Questions1*) $hat is the value of aL3M as the result of the followin" arra& declaration'12

3

Answers : d

Questions 1) $hich of the followin" are primitive t&pes'

b&te6trin"

inte"erFloat

Answers : a.

14) $hat is the ran"e of the char t&pe'

; to 21*; to 21#

; to 21*C1; to 21#C1

(ns. dQuestions15) $hat are primitive data t&pes'

Answers : b&te0 short0 int0 lon"float0 double

boolean

Page 4: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 4/22

charQuestions 2;) $hat are default values of different primitive t&pes'

Answers : int C ;short C ;

b&te C ;lon" C ; l

float C ;.; f double C ;.; d

boolean C falsechar C null

Questions21) ,onvertin" of primitive t&pes to obects can be explicitl&.a)True

b)False

Answers : b.

Questions 22) ow do we chan"e the values of the elements of the arra&'

Answers : The arra& subscript expression can be used to chan"e the values of the elements

of the arra&.

Questions 23) $hat is final varaible'

Answers : -f a variable is declared as final variable0 then &ou cannot chan"e its value. -t

becomes constant.Questions 2) $hat is static variable'Answers : 6tatic variables are shared b& all instances of a class.

Java perators interview questions with answersQuestions 1) $hat are operators and what are the various t&pes of operators available in

Java'Answers : Operators are special s&mbols used in expressions.

The followin" are the t&pes of operators+(rithmetic operators0

(ssi"nment operators0-ncrement < Eecrement operators0

9o"ical operators0Giwise operators0

,omparison8elational operators and,onditional operators

Questions 2) The operator is used for incrementin" and the CC operator is used fordecrementin".

a)True

b)False

Answers : a.

Questions3) ,omparison89o"ical operators are used for testin" and ma"nitude.

a)Trueb)False

Answers : a.Questions) ,haracter literals are stored as unicode characters.

a)Trueb)False

Answers : a.Questions#) $hat are the 9o"ical operators'

Answers : OP)0 (NE<)0 QOR) (NE NOTS).

Page 5: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 5/22

Questions*) $hat is the operator'Answers :  operator is the modulo operator or reminder operator. -t returns the reminder

of dividin" the first operand b& second operand.) $hat is the value of 111 13'

3#

5

Answers : c.

Questions4) -s <<K a valid operator'

Answers : No.

Questions5) ,an a double value be cast to a b&te'

Answers : Ues

Questions 1;) ,an a b&te obect be cast to a double value '

Answers : No. (n obect cannot be cast to a primitive value.

Questions 11) $hat are order of precedence and associativit&'

Answers : Order of precedence the order in which operators are evaluated in expressions.

(ssociativit& determines whether an expression is evaluated leftCri"ht or ri"htCleft.

Questions12) $hich Java operator is ri"ht associativit&'

Answers : K operator.Questions 13) $hat is the difference between prefix and postfix of CC and operators'Answers : The prefix form returns the increment or decrement operation and returns the

value of the increment or decrement operation.The postfix form returns the current value of all of the expression and then

performs the increment or decrement operation on that value.Questions1) $hat is the result of expression #.# 73027'

The double value 4.*The strin" 774.*7

The lon" value 4.The 6trin" 7#.#3.27

Answers : d

Questions 1#) $hat are the values of x and & 'x K #: & K x:

Answers : x K *: & K *

Questions 1*) $hat are the values of x and @'x K #: @ K x:

Answers : x K *: @ K #

Java !ontrol "tatements inteview questions and answersQuestions 1) $hat are the pro"rammin" constructs'

Answers : a) 6e%uential

b) 6election CC if and switch statements

c) -teration CC for loop0 while loop and doCwhile loop2) class conditional V

public static void main6trin" ar"sLM) Vint i K 2;:

int K ##:int @ K ;:

@ K i W ' i + : 88 ternar& operator6&stem.out.println7The value assi"ned is 7 @):

X

Page 6: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 6/22

X$hat is output of the above pro"ram'

Answers : The value assi"ned is 2;Questions3) The switch statement does not re%uire a brea.

a)Trueb)False

Answers : b.Questions) The conditional operator is otherwise nown as the ternar& operator.

a)Trueb)False

Answers : a.

Questions#) The while loop repeats a set of code while the condition is false.

a)Trueb)False

Answers : b.

Questions*) The doCwhile loop repeats a set of code atleast once before the condition is

tested.

a)Trueb)False

Answers : a.Questions ) $hat are difference between brea and continue'Answers : The brea e&word halts the execution of the current loop and forces control out

of the loop.The continue is similar to brea0 except that instead of haltin" the execution of the loop0 it

starts the next iteration.

Questions4) The for loop repeats a set of statements a certain number of times until acondition is matched.

a)Trueb)False

Answers : a.

Questions5) ,an a for statement loop indefintel&'Answers : Ues.

Questions1;) $hat is the difference between while statement and a do statement8

Answers : ( while statement checs at the be"innin" of a loop to see whether the nextloop iteration should occur.

( do statement checs at the end of a loop to see whether the next iteration of a loopshould occur. The do statement will alwa&s execute the bod& of a loop at least once.

Interview questions on #ava !lasses and $ethodsQuestions1) $hich is used to "et the value of the instance variables'

Answers : Eot notation.

Questions2) The new operator creates a sin"le instance named class and returns a

reference to that obect.a)Trueb)False

Answers : a.

Questions3) ( class is a template for multiple obects with similar features.a)True

b)False

Answers : a.

Questions ) $hat is mean b& "arba"e collection'

Page 7: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 7/22

Answers : $hen an obect is no lon"er referred to b& an& variable0 Java automaticall&reclaims memor& used b& that obect. This is nown as "arba"e collection.

Questions#) $hat are methods and how are the& defined'Answers : ethods are functions that operate on instances of classes in which the& are

defined.Obects can communicate with each other usin" methods and can call methods inother classes.

ethod definition has four parts. The& are name of the method0 t&pe of obect or primitivet&pe the method returns0 a list of parameters and the bod& of the method.

( methodYs si"nature is a combination of the first three parts mentioned above.

Questions*) $hat is callin" method'

Answers : ,allin" methods are similar to callin" or referrin" to an instance variable. Thesemethods are accessed usin" dot notation.

/x+ ob.methodnameparam10param2)

Questions) $hich method is used to determine the class of an obect'

Answers : "et,lass ) method can be used to find out what class the belon"s to. This classis defined in the obect class and is available to all obects.

Questions 4) (ll the classes in ava.lan" paca"e are automaticall& imported when

a pro"ram is compiled.a)True

b)FalseAnswers : a.Questions 5) ow can class be imported to a pro"ram'

Answers : To import a class0 the import e&word should be used as shown.:import classname:

Questions 1;) ow can class be imported from a paca"e to a pro"ram'Answers : import ava . paca"ename . classname or) import ava.paca"e name.D:

Questions 11) $hat is a constructor'Answers : ( constructor is a special ind of method that determines how an obect is

initiali@ed when created.Questions 12) $hich e&word is used to create an instance of a class'

Answers : new.

Questions 13) $hich method is used to "arba"e collect an obect'Answers : finali@e ).

Questions 1) ,onstructors can be overloaded lie re"ular methods.

a)Trueb)False

Answers : a.

Questions 1#) $hat is castin"'

Answers : ,astin" is bused to convert the value of one t&pe to another.

Questions 1*) ,astin" between primitive t&pes allows conversion of one primitive t&pe to

another.

a)Trueb)False

Answers : a.Questions 1) ,astin" occurs commonl& between numeric t&pes.

a)Trueb)False

Answers : a.Questions 14) Goolean values can be cast into an& other primitive t&pe.

a)True

Page 8: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 8/22

b)FalseAnswers : b.

Questions 15) ,astin" does not affect the ori"inal obect or value.a)True

b)FalseAnswers : a.

Questions 2;) $hich cast must be used to convert a lar"er value into a smaller one'Answers : /xplicit cast.

Questions 21) $hich cast must be used to cast an obect to another class'

Answers : 6pecific cast.

Questions 22) $hich of the followin" features are common to both Java < ,'(.The class declaration

b.The access modifiersc.The encapsulation of data < methods with in obects

d.The use of pointers

Answers : a0b0c.

Questions 23) $hich of the followin" statements accuratel& describe the use of access

modifiers within a class definition'a.The& can be applied to both data < methods

b.The& must precede a classYs data variables or methodsc.The& can follow a classYs data variables or methodsd.The& can appear in an& order

e.The& must be applied to data variables first and then to methodsAnswers : a0b0d.

Questions 2) 6uppose a "iven instance variable has been declared private.,an this instance variable be manipulated b& methods out side its class'

a.&esb.no

Answers : b.Questions 2#) $hich of the followin" statements can be used to describe a public method'

a.-t is accessible to all other classes in the hierarch&

b.-t is accessablde onl& to subclasses of its parent classc.-t represents the public interface of its classd.The onl& wa& to "ain access to this method is b& callin" one of the public class

methods

Answers : a0c.

Questions 2*) $hich of the followin" t&pes of class members can be part of the internalpart of a class'

a.!ublic instance variablesb.!rivate instance variables

c.!ublic methodsd.!rivate methods

Answers : b0d.

Questions 2) Uou would use the AAAA operator to create a sin"le instance of a named

class.a.new

b.dotAnswers : a.

Questions 24) $hich of the followin" statements correctl& describes the relation betweenan obect and the instance variable it stores'

a./ach new obect has its own distinctive set of instance variablesb./ach obect has a cop& of the instance variables of its class

c.the instance variable of each obect are seperate from the variables of other obects

Page 9: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 9/22

d.The instance variables of each obect are stored to"ether with the variables of otherobects

Answers : a0b0c.Questions 25) -f no input parameters are specified in a method declaration then the

declaration will include AA.a.an empt& set of parantheses

b.the term voidAnswers : a.

Questions 3;) $hat are the functions of the dot.) operator'a.-t enables &ou to access instance variables of an& obects within a class

b.-t enables &ou to store values in instance variables of an obectc.-t is used to call obect methods

d.-t is to create a new obect

Answers : a0b0c.

Questions 31) $hich of the followin" can be referenced b& this variable'a.The instance variables of a class onl&

b.The methods of a class onl&

c.The instance variables and methods of a class

Answers : c.

Questions 32) The this reference is used in conunction with AAAmethods.a.staticb.nonCstatic

Answers : b.Questions 33) $hich of the followin" operators are used in conunction with the this and

super references'a.The new operator

b.The instanceof operatorc.The dot operator

Answers : c.Questions 3) ( constructor is automaticall& called when an obect is instantiated

a. true

b. falseAnswers : a.

Questions 3#) $hen ma& a constructor be called without specif&in" ar"uments'

a. $hen the default constructor is not calledb. $hen the name of the constructor differs from that of the class

c. $hen there are no constructors for the class

Answers : c.

Questions 3*) /ach class in ava can have a finali@er methoda. true

b.false

Answers : a.

Questions 3) $hen an obect is referenced0 does this mean that it has been identified b&

the finali@er method for "arba"e collection'

a.&esb.no

Answers : b.Questions 34) Gecause finali@e ) belon"s to the ava.lan".Obect class0 it is present in all

 AAA.a.obects

b.classesc.methods

Answers : b.

Page 10: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 10/22

Questions 35) -dentif& the true statements about [email protected].( class ma& have onl& one finali@e method

b.Finali@ers are mostl& used with simple classesc.Finali@er overloadin" is not allowed

Answers : a0c.Questions ;) $hen &ou write finali@e) method for &our class0 &ou are overridin" a

finali@erinherited from a super class.

a.trueb.false

Answers : a.

Questions 1) Java memor& mana"ement mechanism "arba"e collects obects which are

no lon"er referenceda true

b.false

Answers : a.

Questions 2) are obects referenced b& a variable candidates for "arba"e collection when

the variable "oes out of scope'a &es

b. noAnswers : a.Questions 3) JavaYs "arba"e collector runs as a AAA priorit& thread waitin" for AApriorit&

threads to relin%uish the processor.a.hi"h

b.lowAnswers : a0b.

Questions ) The "arba"e collector will run immediatel& when the s&stem is out ofmemor&

a.trueb.false

Answers : a.

Questions #) Uou can explicitl& drop a obect reference b& settin" the value of a variablewhose data t&pe is a reference t&pe to AAA

Answers : null

Questions *) $hen mi"ht &our pro"ram wish to run the "arba"e collecter'a. before it enters a computeCintense section of code

b. before it enters a memor&Cintense section of codec. before obects are finali@ed

d. when it nows there will be some idle time

Answers : a0b0d

Questions ) For externali@able obects the class is solel& responsible for the externalformat of its contents

a.true

b.false

Answers : aQuestions 4) $hen an obect is stored0 are all of the obects that are reachable from that

obect stored as well'a.true

b.falseAnswers : a

Questions 5) The defaultAA of obects protects private and trancient data0 and supportsthe AA of the classes

a.evolution

Page 11: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 11/22

b.encodin"Answers : b0a.

Questions #;) $hich are e&words in Java'a) NZ99

b) si@eof c) friend

d) extendse) s&nchroni@ed

Answers : d and e

Questions #1) $hen must the main class and the file name coincide'

Answers :$hen class is declared public.

Questions #2) $hat are different modifiers'

Answers : public0 private0 protected0 default0 static0 trancient0 volatile0 final0 abstract.

Questions #3) $hat are access modifiers'

Answers : public0 private0 protected0 default.

Questions #) $hat is meant b& 7!assin" b& value7 and 7 !assin" b& reference7'

Answers : obects > pass b& referrence

ethods C pass b& value

Questions ##) -s a class a subclass of itself'

Answers : ( class is a subclass itself.

Questions #*) $hat modifiers ma& be used with topClevel class'

Answers : public0 abstract0 final.Questions #) $hat is an example of pol&morphism'

-nner class(non&mous classes

ethod overloadin"ethod overridin"

Answers : c

 #ava Pac%ages and inter&ace interview questions1) $hat are paca"es ' what is use of paca"es '

Answers :The paca"e statement defines a name space in which classes are stored.-f &ouomit the paca"e0 the classes are put into the default paca"e.

6i"nature... paca"e p":Zse+ D -t specifies to which paca"e the classes defined in a file belon"s to. D !aca"e is

both namin" and a visibilit& control mechanism.2) $hat is difference between importin" 7ava.applet.(pplet7 and 7ava.applet.D:7 '

Answers :7ava.applet.(pplet7 will import onl& the class (pplet from the paca"e

 ava.applet$here as 7ava.applet.D7 will import all the classes from ava.applet paca"e.

3) $hat do &ou understand b& paca"e access specifier'

Answers : public+ (n&thin" declared as public can be accessed from an&whereprivate+ (n&thin" declared in the private can=t be seen outside of its class.

default+ -t is visible to subclasses as well as to other classes in the same paca"e.) $hat is interface' $hat is use of interface'

Answers : -t is similar to class which ma& contain method=s si"nature onl& but not bodies.ethods declared in interface are abstract methods. $e can implement man& interfaces on

a class which support the multiple inheritance.#) -s it is necessar& to implement all methods in an interface'

Answers : Ues. (ll the methods have to be implemented.

Page 12: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 12/22

*) $hich is the default access modifier for an interface method'Answers : public.

) ,an we define a variable in an interface 'and what t&pe it should be 'Answers : Ues we can define a variable in an interface. The& are implicitl& final and static.

4) $hat is difference between interface and an abstract class'Answers : (ll the methods declared inside an -nterface are abstract. $here as abstract

class must have at least one abstract method and others ma& be concrete or abstract.-n -nterface we need not use the e&word abstract for the methods.

5) G& default0 all pro"ram import the ava.lan" paca"e.True8False

Answers : True1;) Java compiler stores the .class files in the path specified in ,9(66!(T

environmental variable.True8False

Answers : False

11) ZserCdefined paca"e can also be imported ust lie the standard paca"es.

True8False

Answers : True

12) $hen a pro"ram does not want to handle exception0 the AAAAAAclass is used.Answers : Throws13) The main subclass of the /xception class is AAAAAAA class.

Answers : untime/xception1) Onl& subclasses of AAAAAAclass ma& be cau"ht or thrown.

Answers : Throwable1#) (n& userCdefined exception class is a subclass of the AAAAA class.

Answers : /xception1*) The catch clause of the userCdefined exception class should AAAAAA its

Gase class catch clause.Answers : /xception

1) ( AAAAAAA is used to separate the hierarch& of the class while declarin" an

-mport statement.Answers : !aca"e

14) (ll standard classes of Java are included within a paca"e called AAAAA.

Answers : ava.lan"

15) (ll the classes in a paca"e can be simultaneousl& imported usin" AAAA.

Answers : D

2;) ,an &ou define a variable inside an -nterface. -f no0 wh&' -f &es0 how'(ns.+ U/6. final and static

21) ow man& concrete classes can &ou have inside an interface'(ns.+ None

22) ,an &ou extend an interface'

(ns.+ Ues

23) -s it necessar& to implement all the methods of an interface while implementin" theinterface'

(ns.+ No2) -f &ou do not implement all the methods of an interface while implementin" 0 what

specifier should &ou use for the class '(ns.+ abstract

2#) ow do &ou achieve multiple inheritance in Java'Answers : Zsin" interfaces.

2*) ow to declare an interface example'

Page 13: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 13/22

Answers : access class classname implements interface.2) ,an &ou achieve multiple interface throu"h interface'

a)Trueb) false

Answers : a.24) ,an variables be declared in an interface ' -f so0 what are the modifiers'

Answers : Ues. final and static are the modifiers can be declared in an interface.25) $hat are the possible access modifiers when implementin" interface methods'

Answers : public.3;) ,an anon&mous classes be implemented an interface'

Answers : Ues.31) -nterfaces can=t be extended.

a)Trueb)False

Answers : b.32) Name interfaces without a method'

Answers : 6eriali@able0 ,loneble < emote.

33) -s it possible to use few methods of an interface in a class ' -f so0 how'

Answers : Ues. Eeclare the class as abstract.

Java E'ception (andling interview questionsQuestions 1) $hat is the difference between [throw= and [throws= '(nd it=s application'

Answers : /xceptions that are thrown b& ava runtime s&stems can be handled b& Tr& andcatch blocs. $ith throw exception we can handle the exceptions thrown b& the pro"ram

itself. -f a method is capable of causin" an exception that it does nothandle0 it must specif& this behavior so the callers of the method can "uard

a"ainst that exception.Questions 2) $hat is the difference between [/xception= and [error= in ava'

Answers : /xception and /rror are the subclasses of the Throwable class. /xception class isused for exceptional conditions that user pro"ram should catch. $ith exception class we can

subclass to create our own custom exception./rror defines exceptions that are not excepted to be cau"ht b& &ou pro"ram. /xample is

6tac Overflow.Questions 3) $hat is [esource lea='

Answers : Freein" up other resources that mi"ht have been allocated at the be"innin" of amethod.

Questions )$hat is the [finall&= bloc'

Answers : Finall& bloc will execute whether or not an exception is thrown. -f an exception

is thrown0 the finall& bloc will execute even if no catch statement match the exception. (n&time a method is about to return to the caller from inside tr&8catch bloc0 via an uncau"ht

exception or an explicit return statement0 the finall& clause is also execute.

Questions#) ,an we have catch bloc without tr& bloc' -f so when'

Answers : No. Tr&8,atch or Tr&8finall& form a unit.

Questions *) $hat is the difference between the followin" statements',atch /xception e)0

,atch /rror err)0,atch Throwable t)

Answers :

Questions ) $hat will happen to the /xception obect after exception handlin"'

Page 14: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 14/22

Answers : -t will "o for \arba"e ,ollector. (nd frees the memor&.Questions 4) ow man& /xceptions we can define in [throws= clause'

Answers : $e can define multiple exceptions in throws clause.6i"nature is..

t&pe methodCname parameterClist) throws exceptionClist

Questions 5) The finall& bloc is executed when an exception is thrown0 even if no catchmatches it.

True8False

Answers : True

Questions 1;) The subclass exception should precede the base class exception when usedwithin the catch clause.

True8False

Answers : True

Questions 11) /xceptions can be cau"ht or rethrown to a callin" method.True8False

Answers : True

Questions 12) The statements followin" the throw e&word in a pro"ram are not executed.True8False

Answers : TrueQuestions 13) The to6trin" ) method in the userCdefined exception class is overridden.True8False

Answers : True

Jave $)*+I +(EADI-. interview questions with AnswersQuestions 1) $hat are the two t&pes of multitasin"'

Answers : 1.processCbased2.ThreadCbased

Questions2) $hat are the two wa&s to create the thread'

Answers : 1.b& implementin" unnable

2.b& extendin" ThreadQuestions 3) $hat is the si"nature of the constructor of a thread class'

Answers : Threadunnable threadob06trin" threadName)

Questions ) $hat are all the methods available in the unnable -nterface'

Answers : run)

Questions #) $hat is the data t&pe for the method is(live) and this method is

available in which class'

Answers : boolean0 Thread

Questions *) $hat are all the methods available in the Thread class'

Answers : 1.is(live)2.oin)

3.resume)

.suspend)#.stop)

*.start).sleep)

4.destro&)) $hat are all the methods used for -nter Thread communication and what is the class in

which these methods are defined'Answers :1. wait)0notif&) < notif&all)

2. Obect class

Page 15: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 15/22

4) $hat is the mechanisam defind b& ava for the esources to be used b& onl& one Threadat a time'

Answers : 6&nchronisation5) $hat is the procedure to own the moniter b& man& threads'

Answers : not possible1;) $hat is the unit for 1;;; in the below statement'

ob.sleep1;;;)Answers : lon" milliseconds

11) $hat is the data t&pe for the parameter of the sleep) method'

Answers : lon"

12) $hat are all the values for the followin" level'maxCpriorit&

minCpriorit&normalCpriorit&

Answers : 1;010#13) $hat is the method available for settin" the priorit&'

Answers : set!riorit&)

1) $hat is the default thread at the time of startin" the pro"ram'

Answers : main thread

1#) The word s&nchroni@ed can be used with onl& a method.True8 FalseAnswers : False

1*) $hich priorit& Thread can prompt the lower primar& Thread'Answers : i"her !riorit&

1) ow man& threads at a time can access a monitor'Answers : one

14) $hat are all the four states associated in the thread'Answers : 1. new 2. runnable 3. bloced . dead

15) The suspend)method is used to teriminate a thread'True 8False

Answers : False

2;) The run) method should necessar& exists in clases created as subclass of thread'True 8False

Answers : True

21) $hen two threads are waitin" on each other and canYt proceed the pro"rame is said tobe in a deadloc'

True8False

Answers : True

22) $hich method waits for the thread to die '

Answers : oin) method

23) $hich of the followin" is true'

1) wait)0notif&)0notif&all) are defined as final < can be called onl& from with in a

s&nchroni@ed method

2) (mon" wait)0notif&)0notif&all) the wait) method onl& throws -O/xception3) wait)0notif&)0notif&all) < sleep) are methods of obect class

12

31 < 2

102 < 3Answers : E

2) \arba"e collector thread belon"s to which priorit&'

Page 16: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 16/22

Answers : lowCpriorit&2#) $hat is meant b& timeslicin" or time sharin"'

Answers : Timeslicin" is the method of allocatin" ,!Z time to individual threads in apriorit& schedule.

2*) $hat is meant b& daemon thread' -n ava runtime0 what is itYs role'Answers : Eaemon thread is a low priorit& thread which runs intermittentl& in the

bac"round doin" the "arba"e collection operation for the ava runtime s&stem.

Java Inheritance interview questions with answersQuestions 1) $hat is the difference between superclass < subclass'

Answers : ( super class is a class that is inherited whereas subclass is a class that does the

inheritin".

Questions 2) $hich e&word is used to inherit a class'

Answers : extends

Questions 3) 6ubclasses methods can access superclass members8 attributes at all times'

True8False

Answers : False

Questions ) $hen can subclasses not access superclass members'Answers : $hen superclass is declared as private.

Questions #) $hich class does be"in Java class hierarch&'Answers : Obect class

Questions *) Obect class is a superclass of all other classes'True8False

Answers : TrueQuestions ) Java supports multiple inheritance'

True8FalseAnswers : False

Questions 4) $hat is inheritance'

Answers : Eerivin" an obect from an existin" class. -n the other words0 -nheritance is the

process of inheritin" all the features from a classQuestions 5) $hat are the advanta"es of inheritance'

Answers : eusabilit& of code and accessibilit& of variables and methods of the superclassb& subclasses.

Questions1;) $hich method is used to call the constructors of the superclass from thesubclass'

Answers : superar"ument)

Questions 11) $hich is used to execute an& method of the superclass from the subclass'

Answers : super.methodCnamear"uments)

Questions 12) $hich methods are used to destro& the obects created b& the constructormethods'

Answers : finali@e)

Questions 13) $hat are abstract classes'Answers : (bstract classes are those for which instances can=t be created.

Questions 1) $hat must a class do to implement an interface'Answers : -t must provide all of the methods in the interface and identif& the interface in

its implements clause.Questions 1#) $hich methods in the Obect class are declared as final'

Answers : "et,lass)0 notif&)0 notif&(ll)0 and wait)Questions 1*) Final methods can be overridden.

True8False

Page 17: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 17/22

Answers : FalseQuestions 1) Eeclaration of methods as final results in faster execution of the pro"ram'

True8FalseAnswers : True

Questions 14) Final variables should be declared in the be"innin"'True8False

Answers : TrueQuestions 15) ,an we declare variable inside a method as final variables' $h&'

Answers : ,annot because0 local variable cannot be declared as final variables.

Questions2;) ,an an abstract class ma& be final'

Answers : (n abstract class ma& not be declared as final.

Questions 21) Eoes a class inherit the constructors of itYs super class'

Answers : ( class does not inherit constructors from an& of itYs super classes.

Questions 22) $hat restrictions are placed on method overloadin"'

Answers : Two methods ma& not have the same name and ar"ument list but differentreturn t&pes.

Questions 23) $hat restrictions are placed on method overridin"'

Answers : Overridden methods must have the same name 0 ar"ument list 0 and returnt&pe. The overridin" method ma& not limit the access of the method it overridees.The

overridin" method ma& not throw an& exceptions that ma& not be thrown b& the overriddenmethod.Questions 2) $hat modifiers ma& be used with an inner class that is a member of an

outer class'Answers : a nonClocal) inner class ma& be declared as public0 protected0 private0 static0

final or abstract.Questions 2#) ow this) is used with constructors'

Answers : this) is used to invoe a constructor of the same classQuestions 2*) ow super) used with constructors'

Answers : super) is used to invoe a super class constructorQuestions 2) $hich of the followin" statements correctl& describes an interface'

a)-tYs a concrete class

b)-tYs a superclassc)-tYs a t&pe of abstract class

Answers : c

24) (n interface contains AA methodsa)NonCabstract

b)-mplementedc)unimplemented

Answers :c

STRING HANDLINGWhich package does define String and StringBuffer classes?Answers : a!a"lang package"Which #ethod can $e used to o$tain the length of the String?Answers : length% & #ethod"Ho' do (ou concatenate Strings?Answers : B( using ) * ) operator"Which #ethod can $e used to co#pare t'o strings for e+ualit(?Answers : e+uals% & #ethod"Which #ethod can $e used to perfor# a co#parison $et'een strings that

Page 18: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 18/22

ignores case differences?Answers : e+ualsIgnore,ase% & #ethod"What is the use of !alue-f% & #ethod?Answers : !alue-f% & #ethod con!erts data fro# its internal for#at into ahu#an.reada$le for#"What are the uses of toLo'er,ase% & and to/pper,ase% & #ethods?Answers : The #ethod toLo'er,ase% & con!erts all the characters in astring fro# uppercase tolo'ercase"The #ethod to/pper,ase% & con!erts all the characters in a string fro#lo'ercase touppercase"Which #ethod can $e used to find out the total allocated capacit( of aStrinBuffer?

Answers : capacit(% & #ethod"Which #ethod can $e used to set the length of the $uffer 'ithin aStringBuffer o$ect?Answers : setLength% &"What is the difference $et'een String and StringBuffer?Answers : String o$ects are constants0 'hereas StringBuffer o$ects arenot"String class supports constant strings0 'hereas StringBuffer class supportsgro'a$le0 #odifia$le strings"What are 'rapper classes?Answers : Wrapper classes are classes that allo' pri#iti!e t(pes to $eaccessed as o$ects"Which of the follo'ing is not a 'rapper class?StringIntegerBoolean,haracter Answers : a"What is the output of the follo'ing progra#?

pu$lic class 1uestion 2pu$lic static !oid #ain%String args34& 2String s5 6 )a$c)7String s8 6 )def)7String s9 6 s5"concat%s8"to/pper,ase% & &7S(ste#"out"println%s5*s8*s9&7:

Page 19: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 19/22

:a$cdefa$cdefa$ca$cD;<D;<a$cdefa$cD;<None of the a$o!eAnswers : c"Which of the follo'ing #ethods are #ethods of the String class?delete% &append% &re!erse% &replace% &Answers : d"Which of the follo'ing #ethods cause the String o$ect referenced $( s to$e changed?

s"concat% &s"to/pper,ase% &s"replace% &s"!alue-f% &Answers : a and $"String is a 'rapper class?True<alseAnswers : $"5=& If (ou run the code $elo'0 'hat gets printed out?String s6ne' String%)Bic(cle)&7int iBegin657char i;nd697S(ste#"out"println%s"su$string%iBegin0i;nd&&7Bicicc& ic(d& error> no #ethod #atching su$string%int0char&Answers : $"

5& Gi!en the follo'ing declarationsString s56ne' String%)Hello)&String s86ne' String%)there)&7String s96ne' String%&7Which of the follo'ing are legal operations?s96s5 * s87s96s5 . s87

Page 20: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 20/22

c& s96s5 @ s8d& s96s5 @@ s8Answers : a"5& Which of the follo'ing state#ents are true?The String class is i#ple#ented as a char arra(0 ele#ents are addressedusing the stringna#e34 con!ention$& Strings are a pri#iti!e t(pe in a!a that o!erloads the * operator forconcatenationc& Strings are a pri#iti!e t(pe in a!a and the StringBuffer is used as the#atching 'rapper t(ped& The siCe of a string can $e retrie!ed using the length propert("Answers : $"

;EL-RING AFA"LANG a!a"lang package is auto#aticall( i#ported into all progra#s"True<alseAnswers : aWhat are the interfaces defined $( a!a"lang?Answers : ,lonea$le0 ,o#para$le and Runna$le"What are the constants defined $( $oth <laot and Dou$le classes?Answers : AFAL/;0INFAL/;0NaN0E-SITIF;IN<INIT0N;GATIF;IN<INIT andTE;"What are the constants defined $( B(te0 Short0 Integer and Long?Answers : AFAL/;0INFAL/; andTE;"

What are the constants defined $( $oth <loat and Dou$le classes?Answers : ARADI0INRADI0AFAL/;0INFAL/; andTE;"What is the purpose of the Runti#e class?

Page 21: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 21/22

Answers : The purpose of the Runti#e class is to pro!ide access to thea!a runti#e s(ste#"What is the purpose of the S(ste# class?Answers : The purpose of the S(ste# class is to pro!ide access to s(ste#resources"Which class is eJtended $( all other classes?Answers : -$ect class is eJtended $( all other classes"Which class can $e used to o$tain design infor#ation a$out an o$ect?Answers : The ,lass class can $e used to o$tain infor#ation a$out ano$ectKs design"Which #ethod is used to calculate the a$solute !alue of a nu#$er?Answers : a$s% & #ethod"What are ; and EI?Answers : ; is the $ase of the natural logarith# and EI is the #athe#atical

!alue pi"Which of the follo'ing classes is used to perfor# $asic console I-?S(ste#Securit(anagerathRunti#eAnswers : a"Which of the follo'ing are true?The ,lass class is the superclass of the -$ect class"The -$ect class is final"The ,lass class can $e used to load other classes"The ,lassLoader class can $e used to load other classes"Answers : c and d"Which of the follo'ing #ethods are #ethods of the ath class?a$solute% &log% &cosine% &sine% &Answers : $"

Which of the follo'ing are true a$out the ;rror and ;Jception classes?Both classes eJtend Thro'a$le"The ;rror class is final and the ;Jception class is not"The ;Jception class is final and the ;rror is not"Both classes i#ple#ent Thro'a$le"Answers : a"Which of the follo'ing are true?

Page 22: java interview que.docx

8/9/2019 java interview que.docx

http://slidepdf.com/reader/full/java-interview-quedocx 22/22

The Foid class eJtends the ,lass class"The <loat class eJtends the Dou$le class"The S(ste# class eJtends the Runti#e class"The Integer class eJtends the Nu#$er class"Answers : d"

5=& Which of the follo'ing 'ill output .M"S(ste#"out"println%ath"floor%.M"=&&7S(ste#"out"println%ath"round%.M"=&&7S(ste#"out"println%ath"ceil%.M"=&&7d& S(ste#"out"println%ath"in%.M"=&&7Answers : c"

5& Which of the follo'ing are !alid state#entsa& pu$lic class (,alc eJtends ath$& ath"#aJ%s&7c& ath"round%"05&7d& ath"#od%M05&7e& None of the a$o!e"Answers : e"5& What 'ill happen if (ou atte#pt to co#pile and run the follo'ing code?Integer ten6ne' Integer%5&7Long nine6ne' Long %&7S(ste#"out"println%ten * nine&7int i657S(ste#"out"println%i * ten&75 follo'ed $( 85 follo'ed $( 55;rror> ,anOt con!ert a!a lang Integerd& 5 follo'ed $( 5Answers : c"