Quiz
Java quiz
Create a free account to finish this quiz
Save your progress and see your final score.
Already have an account? Sign in
Questions in this quiz (70)
1Select the different types of access modifiers in Java
- APrivate
- BProtected
- CDefault
- DPublic
- ERestricted
- FGlobal
2The FINAL keyword can be assigned to
- AClass level variable
- Bmethod
- Cclass
- DObjects
- EPackages
3What happens if the FINAL word is assiged to a variable?
- AIt behaves like a constant
- BThe value can change
4What happens if the FINAL keyword is assigned to a method
- AIt cannot be overriden in its child class
- BIt cannot be overriden in its child class but it can be overriden if the child class has a child class that implements it
5How many times a final object can be instantiated?
- A1
- B2
- CThere is no limit
6What is synchronized keyword?
- AIs used to prevent concurrency, locks the objects to prevent the race condition between threads
- BIf used in a variable the permits that the value gets stored in the main memory to be used and it gets modified for every thread using it by modifying the local variable on each thread
7What is the purpose of the transient variable?
- ATo define the properties of the class that does not need to be serialized
- BTo define properties of the class that needs to be serialized
8What is the strictfp modifier?
- AIt is used with variable only to restrict the floating point calculations and ensures the portability
- BIt is a modifier that lets the static variables to be converted to constants
9Can be used with variables and methods but not with the class
- Astatic keyword
- Bprivate keyword
10What is a static variable?
- AA variable that shares its stance between multiple objects. And changes done by one object to the variable are reflected in other object
- BA variable that cannot be used across methods
11A method that can be accessed without creating the objects is called:
- Astatic method
- Bpublic method
- Cprivate method
12A static method can call only non-static methods and not static methos
- ATrue
- BFalse
13Why static methods cannot access non static variables or methods?
- Abecause static methods can be accessed without instantiating the class
- Bbecause static methods can only be accessed when the class is instantiated.
14What is "throw" keyword?
- Ais used to throw an exception manually
- Bis used to empty the jvm
15Private modifier:
- AIs accessible in the same package?
- BIs accesible in different package?
- CIs not accesible for anyone
16Protected modifier
- AIs accessible for the same package
- BIs accesible for a different package
- CNon accesible for anyone
- DOnly accesible if the class extends the main class
- AIs accessible for the same package
17Default modifier
- AAccessible in the same package
- BAccessible in different package
- CNo accesibe for anyone
18Public modifier
- AAccessible in the same package
- BAccessible in different package
- CNot accesible for anyone
19Why is main method static?
- Abecause there is no need of a class object to access
- Bbecause you only need the class name and the static method name to use it
- Cbecause its the example method
20What is the difference between statuc and instance methods?
- AInstance method belongs to the instance of a class therefore it requires an instance before it can be invoked
- BStatic method belongs to the class itself and not to any class instance so it doesn’t need an instance to be invoked
- CStatic method belongs to the class itself and to any class instance so it does need an instance to be invoked
- DInstance method belongs to the instance of a class therefore it does not requires an instance before it can be invoked
21What is an abstract class?
- AIs called abstract when it contains at least one abstract method
- Babstract classes contains both abstract and defined methods
- Cabstract classes can not be modified once it is created
- Dabstract class contains only constants
- Eabstract class can have public, private, protect, default variables and constants
- Fa class can extend just one abstract class
22An abstract class extended is compulsory to implement all methods
- ATrue
- BFalse
23What is an interface?
- ACan contain only abstract methods
- BOnly have constants because the variables are by default public final
- CA class can implement multiple interfaces
- DImplement interface methods is not mandatory
24New methods on implemened interfaces must be implemented in the classes that implemented the interface
- ATrue
- BFalse
25Does Java support multiple inheritance?
- ATrue
- BFalse
26How is called the problem related to multiple inheritance in Java?
- ADiamond problem
- BSquare problem
- CRubi problem
27Can "THIS" keyword be assigned a null value?
- ATrue
- BFalse
28What are the different types of references in java?
- ASoftReference
- BWeakReference
- CPhantomReference
- DOblicuosReference
- EHardReference
29A SoftReference can be used to implement a cache. An object that is not reachable by a strong reference (that is, not strongly reachable) but is referenced by a soft reference is called softly reachable. A softly reachable object may be garbage collected at the discretion of the garbage collector. This generally means that softly reachable objects will only be garbage collected when free memory is low, but again, it is at the discretion of the garbage collector. Semantically, a soft reference means "keep this object unless the memory is needed."
- ATrue
- BFalse
30A WeakReference is used to implement weak maps. An object that is not strongly or softly reachable, but is referenced by a weak reference is called weakly reachable. A weakly reachable object will be garbage collected during the next collection cycle. This behavior is used in the class java.util.WeakHashMap. A weak map allows the programmer to put key/value pairs in the map and not worry about the objects taking up memory when the key is no longer reachable anywhere else. Another possible application of weak references is the string intern pool. Semantically, a weak reference means "get rid of this object when nothing else references it."
- ATrue
- BFalse
31A PhantomReference is used to reference objects that have been marked for garbage collection and have been finalized, but have not yet been reclaimed. An object that is not strongly, softly or weakly reachable, but is referenced by a phantom reference is called phantom reachable. This allows for more flexible cleanup than is possible with the finalization mechanism alone. Semantically, a phantom reference means "this object is no longer needed and has been finalized in preparation for being collected."
- ATrue
- BFalse
32How to change the heap size of a JVM?
- AUsing -Xms and -Xmx switches to specify initial and maximum
- BUsing -Xxms and -Xsmx switches to specify initial and maximum
- CUsing -Xsms and -Xxmx switches to specify initial and maximum
33What is instanceof?
- AIs a reserved word of java, is used to identify wheter the object is type of a particular class or its subclass
- BIs a method of java.lang.Class that is used to identify object of a particular class.
34what is isInstance(obj)?
- AIs a method of java.lang.Class that is used to identify object of a particular class.
- Bis used to identify whether the object is type of a particular class or its subclass
35Java supports...
- Aonly pass by value
- Bonly pass by reference
- Cboth
36Memory leak is when an unreferenced object that will never be used again still hangs around in memory and does not get garbage collected.
- ATrue
- BFalse
37Diferences between == and equals()
- A== operator is used to compare the references of the objects.
- B== operator is not used to compare the references of the objects.
- Cequals() method can be used to compare the values of two objects.
- Dequals() method can not be used to compare the values of two objects.
38Can an abstract class have a static method?
- AYes and can be accessed by any other class, even a interface
- BYes but cannot be accessed by a concret class
39Abstract class have default and parameterized constructors
- ATrue
- BFalse
40What is the difference between string builder and string buffer?
- AString builder is unsynchronized
- BString builder is more efficient
- CString builder is synchronized
41Select the correct answers
- Afinal - declaread as constant. A final variable act as constant, a final class is immutable and a final method cannot be ovrriden.
- Bfinal - handles exception. The finally block is optional and provides a mechanism to clean up regardless of what happens within the try block (except System.exit(0) call). Use the finally block to close files or to release other system resources like database connections, statements etc.
- Cfinalize() - method helps in garbage collection. A method that is invoked before an object is discarded by the garbage collector, allowing it to clean up its state. Should not be used to release non-memory resources like file handles, sockets, database connections etc because Java has only a finite number of these resources and you do not know when the garbage collection is going to kick in to release these non-memory resources through the finalize() method.
- Dfinalize() -handles exception. The finally block is optional and provides a mechanism to clean up regardless of what happens within the try block (except System.exit(0) call). Use the finally block to close files or to release other system resources like database connections, statements etc.
- Efinally - handles exception. The finally block is optional and provides a mechanism to clean up regardless of what happens within the try block (except System.exit(0) call). Use the finally block to close files or to release other system resources like database connections, statements etc.
- Ffinally - declaread as constant. A final variable act as constant, a final class is immutable and a final method cannot be ovrriden.
42How is called the part of the memory access to ge the recent created objects?
- Aheap
- Bstack
43Where are allocated the primitive variables?
- Ain the stack
- Bin the heap
44What is reflection?
- AThe ability to copy methods in runtime
- BThe ability to access to variables and methods even if they are private
45How does the static block works?
- Ait is called only the first time a class is loaded
- Bit is called first everytime the class is loaded
46how many times an init{} block is loaded when a class is loaded?
- Ajust the first time the class is loaded
- Bas many times as the class is loaded
47Why inner class can access only final variable?
- APrincipally because the non-final variables could be out of synch if somehow they are modified
- Binner clause can access to every type of modifier
48What is a fully abstract class?
- AAn abstract class which has all methods as abstract and all fields are public static final.
- BAn abstract class which not neccesarily all methods are abstract
49The abiltiy to define a function in multiple forms is
- APolymorphism
- BOverriding
- COverloading
50What is overriding?
- AOverriding occurs when a class method has the same name and signature as a method in parent class. When you override methods, JVM determines the proper methods to call at the program’s run time, not at the compile time.
- Bis determined at the compile time. It occurs when several methods have same names
51What is overloading?
- A is determined at the compile time. It occurs when several methods have same names
- Bccurs when a class method has the same name and signature as a method in parent class.
52Is the property which allows a Child class to inherit some properties from its parent class.
- AInheritance
- BOverloading
- COverriding
53To what type of access modifier a child class can have access?
- APublic
- BProtected
- CDefault
- DPrivate
54 Is a way of converting real world objects in terms of class. Its a concept of defining an idea in terms of classes or interface.
- AAbstraction
- BEncapsulation
- CAggregation
- DComposition
55Is a relationship where all object have their own lifecycle and there is no owner.
- AEncapsulation
- BAssociation
- CAggregation
- DComposition
56A relationship between two classes like association, however its a directional association, which means it is strictly a one way association. It represents a Has-A relationship.
- AEncapsulation
- BAssociation
- CAggregation
- DComposition
57Overloading is known also as:
- AStatic Polymorphism
- BOverriding
- CSuper Polymorphism
58Characteristics of ArrayList
- AArrayList is not thread safe
- BArrayList is thread safe
- CArrayList doubles its size if it runs out of space
- DArrayList increase its size by 50% if it runs out of space
- EArrayList is faster than Vector
- FVector is faster than ArrayList
59Characteristics of Vector
- AVector is thread safe
- BVector is not thread safe
- CVector doubles its size in case it runs out of room
- DVector increase its size by 50% in case it runs out of room
- EVector is faster than ArrayList
- FVector is slower than ArrayList
60Differences between HashMap and HashTable
- AHashMap permits null values and only one null key
- BHash tables doesnt allow key or values as null
- CHashMap does not permits null values and only one null key
- DHash tables allow key or values as null
- EHashMap is fail-safe and HashTable is not fail-safe
- FHashMap is not fail-safe and HashTable is fail-safe
- GHashMap is not synchronized in nature but hash table is
- HHashMap is synchronized in nature but hash table is not
61Classes that implement List Interface
- AArrayList
- BVector
- CLinkedList
- DHashMap
- EHashTable
- FSortedSet
- GTreeSet
- HHashSet
62Characteristics of ArrayList
- A It is a resizable array implementation
- BCan be increased dynamically also operations like add,remove and get can be formed once the object is created.
- CEnsures that the data is retrieved in the manner it was stored.
- DIs not thread-safe.
- EMethods are wrapped around a synchronized block.
- FImplements Queue interface too and provide FIFO (First In First Out) operation
63Characteristics of Vector
- AIs thread-safe implementation of ArrayList.
- BMethods are wrapped around a synchronized block
- CImplements Queue interface
- DIs faster than ArrayList
64LinkedList characteristics
- AImplements Queue interface
- BProvide FIFO (First In First Out) operation for add operation
- CFaster than ArrayList if its mainly used for insertion and deletion
- DIs thread-safe implementation of ArrayList.
65Which classes implement Set Interface?
- AArrayList
- BVector
- CLinkedList
- DSortedSet
- ETreeSet
- FHashSet
66What is set?
- AIs a collection that contains no duplicate elements
- BIs a collection that contains duplicates
67Characteristics of Sorted Set
- AInterface allows the data to be iterated in the ascending order or sorted on the basis of Comparator or Comparable interface
- BIt does not guarantee that the order will remain constant over time
68Characteristics of TreeSet
- AProvides guaranteed log(n) time cost for the basic operations
- BThe class is not synchronized
- CGuarantees that elements of set will be sorted
- DThe class is synchronized
- EIt does not guarantee that the order of elements will remain constant over time
69Characteristics of HashSet
- AIt does not guarantee that the order of elements will remain constant over time
- BOffers constant time performance for the basic operations (add, remove, contains and size)
- CAcepts duplicated elements
70 What is difference between List and a Set?
- AList can contain duplicate values but Set doesn't allow.
- BList allows retrieval of data to be in same order in the way it is inserted but Set doesnt ensures the sequence in which data can be retrieved.(Except HashSet)
- CList allows retrieval of data to be in same order in the way it is inserted but Set doesnt ensures the sequence in which data can be retrieved.
- DList can not contain duplicate values but Set allows.
Information
- Description
- Quiz on Java quiz, created by Misael Pinedo on 21/03/2015.
- Author
- Misael Pinedo
- Language
- Español
- Views
- 3
- Tags
- Rating
- No ratings yet Rate this quiz