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

Core Java - Interview Questions and Answers

This document contains interview questions and answers related to Java programming. Some key points covered include: - Java is platform independent and code can be run on any system with a JVM. - The JVM is platform specific while the JDK includes tools for development and execution. - Java supports single inheritance of classes but interfaces can extend multiple other interfaces. - Abstract classes, interfaces, static and final modifiers are discussed in detail.

Uploaded by

ratneshmicro
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
389 views

Core Java - Interview Questions and Answers

This document contains interview questions and answers related to Java programming. Some key points covered include: - Java is platform independent and code can be run on any system with a JVM. - The JVM is platform specific while the JDK includes tools for development and execution. - Java supports single inheritance of classes but interfaces can extend multiple other interfaces. - Abstract classes, interfaces, static and final modifiers are discussed in detail.

Uploaded by

ratneshmicro
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

JavaInterviewQuestionsandAnswers

1.WhatisthemostimportantfeatureofJava? Javaisaplatformindependentlanguage. 2.Whatdoyoumeanbyplatformindependence? Platformindependencemeansthatwecanwriteandcompilethejava codeinoneplatform(egWindows)andcanexecutetheclassinanyother supportedplatformeg(Linux,Solaris,etc). 3.WhatisaJVM? JVMisJavaVirtualMachinewhichisaruntimeenvironmentforthe compiledjavaclassfiles. 4.AreJVM'splatformindependent? JVM'sarenotplatformindependent.JVM'sareplatformspecificrun timeimplementationprovidedbythevendor. 5.WhatisthedifferencebetweenaJDKandaJVM? JDKisJavaDevelopmentKitwhichisfordevelopmentpurposeandit includesexecutionenvironmentalso.ButJVMispurelyaruntime environmentandhenceyouwillnotbeabletocompileyoursourcefiles usingaJVM. 6.WhatisapointeranddoesJavasupportpointers? Pointerisareferencehandletoamemorylocation.Improperhandlingof pointersleadstomemoryleaksandreliabilityissueshenceJavadoesn't supporttheusageofpointers. 7.Whatisthebaseclassofallclasses? java.lang.Object 8.DoesJavasupportmultipleinheritance? Javadoesn'tsupportmultipleinheritance. 9.IsJavaapureobjectorientedlanguage? Javausesprimitivedatatypesandhenceisnotapureobjectoriented language.

JavaInterviewQuestionsandAnswers
10.Arearraysprimitivedatatypes? InJava,Arraysareobjects. 11.WhatisdifferencebetweenPathandClasspath? PathandClasspathareoperatingsystemlevelenvironmentvariales. Pathisuseddefinewherethesystemcanfindtheexecutables(.exe)files andclasspathisusedtospecifythelocation.classfiles. 12.Whatarelocalvariables? Localvaraiablesarethosewhicharedeclaredwithinablockofcodelike methods.Localvariablesshouldbeinitialisedbeforeaccessingthem. 13.Whatareinstancevariables? Instancevariablesarethosewhicharedefinedattheclasslevel.Instance variablesneednotbeinitializedbeforeusingthemastheyare automaticallyinitializedtotheirdefaultvalues. 14.HowtodefineaconstantvariableinJava? Thevariableshouldbedeclaredasstaticandfinal.Soonlyonecopyof thevariableexistsforallinstancesoftheclassandthevaluecan'tbe changedalso. staticfinalintPI=2.14;isanexampleforconstant. 15.Shouldamain()methodbecompulsorilydeclaredinalljavaclasses? Nonotrequired.main()methodshouldbedefinedonlyifthesourceclass isajavaapplication. 16.Whatisthereturntypeofthemain()method? Main()methoddoesn'treturnanythinghencedeclaredvoid. 17.Whyisthemain()methoddeclaredstatic? main()methodiscalledbytheJVMevenbeforetheinstantiationofthe classhenceitisdeclaredasstatic. 18.Whatisthearguementofmain()method? main()methodacceptsanarrayofStringobjectasarguement.

JavaInterviewQuestionsandAnswers
19.Canamain()methodbeoverloaded? Yes.Youcanhaveanynumberofmain()methodswithdifferentmethod signatureandimplementationintheclass. 20.Canamain()methodbedeclaredfinal? Yes.Anyinheritingclasswillnotbeabletohaveit'sowndefaultmain() method. 21.Doestheorderofpublicandstaticdeclarationmatterinmain() method? No.Itdoesn'tmatterbutvoidshouldalwayscomebeforemain(). 22.Canasourcefilecontainmorethanoneclassdeclaration? YesasinglesourcefilecancontainanynumberofClassdeclarationsbut onlyoneoftheclasscanbedeclaredaspublic. 23.Whatisapackage? Packageisacollectionofrelatedclassesandinterfaces.package declarationshouldbefirststatementinajavaclass. 24.Whichpackageisimportedbydefault? java.langpackageisimportedbydefaultevenwithoutapackage declaration. 25.Canaclassdeclaredasprivatebeaccessedoutsideit'spackage? Notpossible. 26.Canaclassbedeclaredasprotected? Aclasscan'tbedeclaredasprotected.onlymethodscanbedeclaredas protected. 27.Whatistheaccessscopeofaprotectedmethod? Aprotectedmethodcanbeaccessedbytheclasseswithinthesame packageorbythesubclassesoftheclassinanypackage. 28.Whatisthepurposeofdeclaringavariableasfinal? Afinalvariable'svaluecan'tbechanged.finalvariablesshouldbe

JavaInterviewQuestionsandAnswers
initializedbeforeusingthem. 29.Whatistheimpactofdeclaringamethodasfinal? Amethoddeclaredasfinalcan'tbeoverridden.Asubclasscan'thave thesamemethodsignaturewithadifferentimplementation. 30.Idon'twantmyclasstobeinheritedbyanyotherclass.Whatshould ido? Youshoulddeclaredyourclassasfinal.Butyoucan'tdefineyourclass asfinal,ifitisanabstractclass.Aclassdeclaredasfinalcan'tbe extendedbyanyotherclass. 31.CanyougivefewexamplesoffinalclassesdefinedinJavaAPI? java.lang.String,java.lang.Matharefinalclasses. 32.Howisfinaldifferentfromfinallyandfinalize()? finalisamodifierwhichcanbeappliedtoaclassoramethodora variable.finalclasscan'tbeinherited,finalmethodcan'tbeoverridden andfinalvariablecan'tbechanged. finallyisanexceptionhandlingcodesectionwhichgetsexecutedwhether anexceptionisraisedornotbythetryblockcodesegment. finalize()isamethodofObjectclasswhichwillbeexecutedbytheJVM justbeforegarbagecollectingobjecttogiveafinalchanceforresource releasingactivity. 33.Canaclassbedeclaredasstatic? Noaclasscannotbedefinedasstatic.Onlyamethod,avariableora blockofcodecanbedeclaredasstatic. 34.Whenwillyoudefineamethodasstatic? Whenamethodneedstobeaccessedevenbeforethecreationoftheobject oftheclassthenweshoulddeclarethemethodasstatic. 35.Whataretherestrictionimposedonastaticmethodorastaticblock ofcode?

JavaInterviewQuestionsandAnswers
Astaticmethodshouldnotrefertoinstancevariableswithoutcreating aninstanceandcannotuse"this"operatortorefertheinstance. 36.Iwanttoprint"Hello"evenbeforemain()isexecuted.Howwillyou acheivethat? Printthestatementinsideastaticblockofcode.Staticblocksget executedwhentheclassgetsloadedintothememoryandevenbeforethe creationofanobject.Henceitwillbeexecutedbeforethemain()method. Anditwillbeexecutedonlyonce. 37.Whatistheimportanceofstaticvariable? staticvariablesareclasslevelvariableswhereallobjectsoftheclass refertothesamevariable.Ifoneobjectchangesthevaluethenthechange getsreflectedinalltheobjects. 38.Canwedeclareastaticvariableinsideamethod? Staticvaraiblesareclasslevelvariablesandtheycan'tbedeclared insideamethod.Ifdeclared,theclasswillnotcompile. 39.WhatisanAbstractClassandwhatisit'spurpose? AClasswhichdoesn'tprovidecompleteimplementationisdefinedasan abstractclass.Abstractclassesenforceabstraction. 40.Canaabstractclassbedeclaredfinal? Notpossible.Anabstractclasswithoutbeinginheritedisofnouseand hencewillresultincompiletimeerror. 41.Whatisuseofaabstractvariable? Variablescan'tbedeclaredasabstract.onlyclassesandmethodscanbe declaredasabstract. 42.Canyoucreateanobjectofanabstractclass? Notpossible.Abstractclassescan'tbeinstantiated. 43.Canaabstractclassbedefinedwithoutanyabstractmethods? Yesit'spossible.Thisisbasicallytoavoidinstancecreationoftheclass. 44.ClassCimplementsInterfaceIcontainingmethodm1andm2

JavaInterviewQuestionsandAnswers
declarations.ClassChasprovidedimplementationformethodm2.Cani createanobjectofClassC? Nonotpossible.ClassCshouldprovideimplementationforallthe methodsintheInterfaceI.SinceClassCdidn'tprovideimplementation form1method,ithastobedeclaredasabstract.Abstractclassescan'tbe instantiated. 45.CanamethodinsideaInterfacebedeclaredasfinal? Nonotpossible.Doingsowillresultincompilationerror.publicand abstractaretheonlyapplicablemodifiersformethoddeclarationinan interface. 46.CananInterfaceimplementanotherInterface? Intefacesdoesn'tprovideimplementationhenceainterfacecannot implementanotherinterface. 47.CananInterfaceextendanotherInterface? YesanInterfacecaninheritanotherInterface,forthatmatteran InterfacecanextendmorethanoneInterface. 48.CanaClassextendmorethanoneClass? Notpossible.AClasscanextendonlyoneclassbutcanimplementany numberofInterfaces. 49.WhyisanInterfacebeabletoextendmorethanoneInterfacebuta Classcan'textendmorethanoneClass? BasicallyJavadoesn'tallowmultipleinheritance,soaClassis restrictedtoextendonlyoneClass.ButanInterfaceisapureabstraction modelanddoesn'thaveinheritancehierarchylikeclasses(doremember thatthebaseclassofallclassesisObject).SoanInterfaceisallowedto extendmorethanoneInterface. 50.CananInterfacebefinal? Notpossible.Doingsosowillresultincompilationerror. 51.CanaclassbedefinedinsideanInterface?

JavaInterviewQuestionsandAnswers
Yesit'spossible. 52.CananInterfacebedefinedinsideaclass? Yesit'spossible. 53.WhatisaMarkerInterface? AnInterfacewhichdoesn'thaveanydeclarationinsidebutstillenforces amechanism. 54.WhichobjectorientedConceptisachievedbyusingoverloadingand overriding? Polymorphism. 55.WhydoesJavanotsupportoperatoroverloading? Operatoroverloadingmakesthecodeverydifficulttoreadandmaintain. Tomaintaincodesimplicity,Javadoesn'tsupportoperatoroverloading. 56.Canwedefineprivateandprotectedmodifiersforvariablesin interfaces? No. 57.WhatisExternalizable? ExternalizableisanInterfacethatextendsSerializableInterface.And sendsdataintoStreamsinCompressedFormat.Ithastwomethods, writeExternal(ObjectOuputout)andreadExternal(ObjectInputin) 58.WhatmodifiersareallowedformethodsinanInterface? Onlypublicandabstractmodifiersareallowedformethodsininterfaces. 59.Whatisalocal,memberandaclassvariable? Variablesdeclaredwithinamethodare"local"variables. Variablesdeclaredwithintheclassi.enotwithinanymethodsare "member"variables(globalvariables). Variablesdeclaredwithintheclassi.enotwithinanymethodsandare definedas"static"areclassvariables. 60.Whatisanabstractmethod?

JavaInterviewQuestionsandAnswers
Anabstractmethodisamethodwhoseimplementationisdeferredtoa subclass. 61.Whatvaluedoesread()returnwhenithasreachedtheendofafile? Theread()methodreturns1whenithasreachedtheendofafile. 62.CanaByteobjectbecasttoadoublevalue? No,anobjectcannotbecasttoaprimitivevalue. 63.Whatisthedifferencebetweenastaticandanonstaticinnerclass? Anonstaticinnerclassmayhaveobjectinstancesthatareassociated withinstancesoftheclass'souterclass.Astaticinnerclassdoesnothave anyobjectinstances. 64.Whatisanobject'slockandwhichobject'shavelocks? Anobject'slockisamechanismthatisusedbymultiplethreadsto obtainsynchronizedaccesstotheobject.Athreadmayexecutea synchronizedmethodofanobjectonlyafterithasacquiredtheobject's lock.Allobjectsandclasseshavelocks.Aclass'slockisacquiredonthe class'sClassobject. 65.Whatisthe%operator? Itisreferredtoasthemoduloorremainderoperator.Itreturnsthe remainderofdividingthefirstoperandbythesecondoperand. 66.Whencananobjectreferencebecasttoaninterfacereference? Anobjectreferencebecasttoaninterfacereferencewhentheobject implementsthereferencedinterface. 67.Whichclassisextendedbyallotherclasses? TheObjectclassisextendedbyallotherclasses. 68.WhichnonUnicodelettercharactersmaybeusedasthefirst characterofanidentifier? ThenonUnicodelettercharacters$and_mayappearasthefirst characterofanidentifier 69.Whatrestrictionsareplacedonmethodoverloading?

JavaInterviewQuestionsandAnswers
Twomethodsmaynothavethesamenameandargumentlistbut differentreturntypes. 70.Whatiscasting? Therearetwotypesofcasting,castingbetweenprimitivenumerictypes andcastingbetweenobjectreferences.Castingbetweennumerictypesis usedtoconvertlargervalues,suchasdoublevalues,tosmallervalues, suchasbytevalues.Castingbetweenobjectreferencesisusedtoreferto anobjectbyacompatibleclass,interface,orarraytypereference. 71.Whatisthereturntypeofaprogram'smain()method? void. 72.Ifavariableisdeclaredasprivate,wheremaythevariablebe accessed? Aprivatevariablemayonlybeaccessedwithintheclassinwhichitis declared. 73.Whatdoyouunderstandbyprivate,protectedandpublic? Theseareaccessibilitymodifiers.Privateisthemostrestrictive,while publicistheleastrestrictive.Thereisnorealdifferencebetween protectedandthedefaulttype(alsoknownaspackageprotected)within thecontextofthesamepackage,howevertheprotectedkeywordallows visibilitytoaderivedclassinadifferentpackage. 74.WhatisDowncasting? Downcastingisthecastingfromageneraltoamorespecifictype,i.e. castingdownthehierarchy 75.Whatmodifiersmaybeusedwithaninnerclassthatisamemberof anouterclass? A(nonlocal)innerclassmaybedeclaredaspublic,protected,private, static,final,orabstract. 76.HowmanybitsareusedtorepresentUnicode,ASCII,UTF16,and UTF8characters? Unicoderequires16bitsandASCIIrequire7bitsAlthoughtheASCII

JavaInterviewQuestionsandAnswers
charactersetusesonly7bits,itisusuallyrepresentedas8bits. UTF8representscharactersusing8,16,and18bitpatterns. UTF16uses16bitandlargerbitpatterns. 77.Whatrestrictionsareplacedonthelocationofapackagestatement withinasourcecodefile? Apackagestatementmustappearasthefirstlineinasourcecodefile (excludingblanklinesandcomments). 78.Whatisanativemethod? Anativemethodisamethodthatisimplementedinalanguageother thanJava. 79.Whatareorderofprecedenceandassociativity,andhowarethey used? Orderofprecedencedeterminestheorderinwhichoperatorsare evaluatedinexpressions.Associatitydetermineswhetheranexpressionis evaluatedlefttorightorrighttoleft. 80.Canananonymousclassbedeclaredasimplementinganinterface andextendingaclass? Ananonymousclassmayimplementaninterfaceorextendasuperclass, butmaynotbedeclaredtodoboth. 81.Whatistherangeofthechartype? Therangeofthechartypeis0to2161(i.e.0to65535.) 82.Whatistherangeoftheshorttype? Therangeoftheshorttypeis(215)to2151.(i.e.32,768to32,767) 83.Whyisn'tthereoperatoroverloading? BecauseC++hasprovenbyexamplethatoperatoroverloadingmakes codealmostimpossibletomaintain. 84.Whatdoesitmeanthatamethodorfieldis"static"? Staticvariablesandmethodsareinstantiatedonlyonceperclass.In

JavaInterviewQuestionsandAnswers
otherwordstheyareclassvariables,notinstancevariables.Ifyouchange thevalueofastaticvariableinaparticularobject,thevalueofthat variablechangesforallinstancesofthatclass.Staticmethodscanbe referencedwiththenameoftheclassratherthanthenameofa particularobjectoftheclass(thoughthatworkstoo).That'showlibrary methodslikeSystem.out.println()work.outisastaticfieldinthe java.lang.Systemclass. 85.Isnullakeyword? Thenullvalueisnotakeyword. 86.Whichcharactersmaybeusedasthesecondcharacterofan identifier,butnotasthefirstcharacterofanidentifier? Thedigits0through9maynotbeusedasthefirstcharacterofan identifierbuttheymaybeusedafterthefirstcharacterofanidentifier. 87.Istheternaryoperatorwrittenx:y?zorx?y:z? Itiswrittenx?y:z. 88.Howisroundingperformedunderintegerdivision? Thefractionalpartoftheresultistruncated.Thisisknownasrounding towardzero. 89.Ifaclassisdeclaredwithoutanyaccessmodifiers,wheremaythe classbeaccessed? Aclassthatisdeclaredwithoutanyaccessmodifiersissaidtohave packageaccess.Thismeansthattheclasscanonlybeaccessedbyother classesandinterfacesthataredefinedwithinthesamepackage. 90.Doesaclassinherittheconstructorsofitssuperclass? Aclassdoesnotinheritconstructorsfromanyofitssuperclasses. 91.NametheeightprimitiveJavatypes. Theeightprimitivetypesarebyte,char,short,int,long,float,double, andboolean. 92.Whatrestrictionsareplacedonthevaluesofeachcaseofaswitch

JavaInterviewQuestionsandAnswers
statement? Duringcompilation,thevaluesofeachcaseofaswitchstatementmust evaluatetoavaluethatcanbepromotedtoanintvalue. 93.Whatisthedifferencebetweenawhilestatementandadowhile statement? Awhilestatementchecksatthebeginningofalooptoseewhetherthe nextloopiterationshouldoccur.Adowhilestatementchecksattheend ofalooptoseewhetherthenextiterationofaloopshouldoccur.Thedo whilestatementwillalwaysexecutethebodyofaloopatleastonce. 94.Whatmodifierscanbeusedwithalocalinnerclass? Alocalinnerclassmaybefinalorabstract. 95.Whendoesthecompilersupplyadefaultconstructorforaclass? Thecompilersuppliesadefaultconstructorforaclassifnoother constructorsareprovided. 96.Ifamethodisdeclaredasprotected,wheremaythemethodbe accessed? Aprotectedmethodmayonlybeaccessedbyclassesorinterfacesofthe samepackageorbysubclassesoftheclassinwhichitisdeclared. 97.Whatarethelegaloperandsoftheinstanceofoperator? Theleftoperandisanobjectreferenceornullvalueandtheright operandisaclass,interface,orarraytype. 98.Aretrueandfalsekeywords? Thevaluestrueandfalsearenotkeywords. 99.WhathappenswhenyouaddadoublevaluetoaString? TheresultisaStringobject. 100.Whatisthediffrencebetweeninnerclassandnestedclass? Whenaclassisdefinedwithinascopeodanotherclass,thenitbecomes innerclass.Iftheaccessmodifieroftheinnerclassisstatic,thenit becomesnestedclass.

JavaInterviewQuestionsandAnswers
101.Cananabstractclassbefinal? Anabstractclassmaynotbedeclaredasfinal. 102.Whatisnumericpromotion? Numericpromotionistheconversionofasmallernumerictypetoa largernumerictype,sothatintegerandfloatingpointoperationsmay takeplace.Innumericalpromotion,byte,char,andshortvaluesare convertedtointvalues.Theintvaluesarealsoconvertedtolongvalues, ifnecessary.Thelongandfloatvaluesareconvertedtodoublevalues,as required. 103.Whatisthedifferencebetweenapublicandanonpublicclass? Apublicclassmaybeaccessedoutsideofitspackage.Anonpublicclass maynotbeaccessedoutsideofitspackage. 104.Towhatvalueisavariableofthebooleantypeautomatically initialized? Thedefaultvalueofthebooleantypeisfalse. 105.Whatisthedifferencebetweentheprefixandpostfixformsofthe++ operator? Theprefixformperformstheincrementoperationandreturnsthevalue oftheincrementoperation.Thepostfixformreturnsthecurrentvalueall oftheexpressionandthenperformstheincrementoperationonthat value. 106.Whatrestrictionsareplacedonmethodoverriding? Overriddenmethodsmusthavethesamename,argumentlist,and returntype.Theoverridingmethodmaynotlimittheaccessofthe methoditoverrides.Theoverridingmethodmaynotthrowany exceptionsthatmaynotbethrownbytheoverriddenmethod. 107.WhatisaJavapackageandhowisitused? AJavapackageisanamingcontextforclassesandinterfaces.Apackage isusedtocreateaseparatenamespaceforgroupsofclassesand interfaces.Packagesarealsousedtoorganizerelatedclassesand

JavaInterviewQuestionsandAnswers
interfacesintoasingleAPIunitandtocontrolaccessibilitytothese classesandinterfaces. 108.Whatmodifiersmaybeusedwithatoplevelclass? Atoplevelclassmaybepublic,abstract,orfinal. 109.Whatisthedifferencebetweenanifstatementandaswitch statement? Theifstatementisusedtoselectamongtwoalternatives.Itusesa booleanexpressiontodecidewhichalternativeshouldbeexecuted.The switchstatementisusedtoselectamongmultiplealternatives.Itusesan intexpressiontodeterminewhichalternativeshouldbeexecuted. 110.Whatarethepracticalbenefits,ifany,ofimportingaspecificclass ratherthananentirepackage(e.g.importjava.net.*versusimport java.net.Socket)? Itmakesnodifferenceinthegeneratedclassfilessinceonlytheclasses thatareactuallyusedarereferencedbythegeneratedclassfile.Thereis anotherpracticalbenefittoimportingsingleclasses,andthisarises whentwo(ormore)packageshaveclasseswiththesamename.Take java.util.Timerandjavax.swing.Timer,forexample.IfIimport java.util.*andjavax.swing.*andthentrytouse"Timer",Igetanerror whilecompiling(theclassnameisambiguousbetweenbothpackages). Let'ssaywhatyoureallywantedwasthejavax.swing.Timerclass,and theonlyclassesyouplanonusinginjava.utilareCollectionand HashMap.Inthiscase,somepeoplewillprefertoimport java.util.Collectionandimportjava.util.HashMapinsteadofimporting java.util.*.ThiswillnowallowthemtouseTimer,Collection,HashMap, andotherjavax.swingclasseswithoutusingfullyqualifiedclassnames in. 111.Canamethodbeoverloadedbasedondifferentreturntypebutsame argumenttype? No,becausethemethodscanbecalledwithoutusingtheirreturntypein whichcasethereisambiquityforthecompiler.

JavaInterviewQuestionsandAnswers
112.Whathappenstoastaticvariablethatisdefinedwithinamethodof aclass? Can'tdoit.You'llgetacompilationerror. 113.Howmanystaticinitializerscanyouhave? Asmanyasyouwant,butthestaticinitializersandclassvariable initializersareexecutedintextualorderandmaynotrefertoclass variablesdeclaredintheclasswhosedeclarationsappeartextuallyafter theuse,eventhoughtheseclassvariablesareinscope. 114.Whatisthedifferencebetweenmethodoverridingandoverloading? Overridingisamethodwiththesamenameandargumentsasina parent,whereasoverloadingisthesamemethodnamebutdifferent arguments 115.WhatisconstructorchainingandhowisitachievedinJava? Achildobjectconstructoralwaysfirstneedstoconstructitsparent (whichinturncallsitsparentconstructor.).InJavaitisdoneviaan implicitcalltothenoargsconstructorasthefirststatement. 116.WhatisthedifferencebetweentheBoolean&operatorandthe&& operator? IfanexpressioninvolvingtheBoolean&operatorisevaluated,both operandsareevaluated.Thenthe&operatorisappliedtotheoperand. Whenanexpressioninvolvingthe&&operatorisevaluated,thefirst operandisevaluated.Ifthefirstoperandreturnsavalueoftruethenthe secondoperandisevaluated.The&&operatoristhenappliedtothefirst andsecondoperands.Ifthefirstoperandevaluatestofalse,the evaluationofthesecondoperandisskipped. 117.WhichJavaoperatorisrightassociative? The=operatorisrightassociative. 118.Canadoublevaluebecasttoabyte? Yes,adoublevaluecanbecasttoabyte. 119.Whatisthedifferencebetweenabreakstatementandacontinue

JavaInterviewQuestionsandAnswers
statement? Abreakstatementresultsintheterminationofthestatementtowhichit applies(switch,for,do,orwhile).Acontinuestatementisusedtoendthe currentloopiterationandreturncontroltotheloopstatement. 120.Canaforstatementloopindefinitely? Yes,aforstatementcanloopindefinitely.Forexample,considerthe following:for(;;); 121.TowhatvalueisavariableoftheStringtypeautomatically initialized? ThedefaultvalueofanStringtypeisnull. 122.Whatisthedifferencebetweenafieldvariableandalocalvariable? Afieldvariableisavariablethatisdeclaredasamemberofaclass.A localvariableisavariablethatisdeclaredlocaltoamethod. 123.Howarethis()andsuper()usedwithconstructors? this()isusedtoinvokeaconstructorofthesameclass.super()isusedto invokeasuperclassconstructor. 124.Whatdoesitmeanthataclassormemberisfinal? Afinalclasscannotbeinherited.Afinalmethodcannotbeoverriddenin asubclass.Afinalfieldcannotbechangedafterit'sinitialized,andit mustincludeaninitializerstatementwhereit'sdeclared. 125.Whatdoesitmeanthatamethodorclassisabstract? Anabstractclasscannotbeinstantiated.Abstractmethodsmayonlybe includedinabstractclasses.However,anabstractclassisnotrequiredto haveanyabstractmethods,thoughmostofthemdo.Eachsubclassofan abstractclassmustoverridetheabstractmethodsofitssuperclassesorit alsoshouldbedeclaredabstract. 126.Whatisatransientvariable? Transientvariableisavariablethatmaynotbeserialized. 127.HowdoesJavahandleintegeroverflowsandunderflows?

JavaInterviewQuestionsandAnswers
Itusesthoseloworderbytesoftheresultthatcanfitintothesizeofthe typeallowedbytheoperation. 128.Whatisthedifferencebetweenthe>>and>>>operators? The>>operatorcarriesthesignbitwhenshiftingright.The>>>zero fillsbitsthathavebeenshiftedout. 129.Issizeofakeyword? Thesizeofoperatorisnotakeyword.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy