Wednesday, 11 February 2015

Introduction to Classes and Methods Part- 2

Introduction to Classes and Methods Part- 2

31) Which of the following can be referenced by this variable?
a.The instance variables of a class only
b.The methods of a class only
c.The instance variables and methods of a class
Ans: c.

32) The this reference is used in conjunction with ___methods.
a.static
b.non-static
Ans: b.

33) Which of the following operators are used in conjunction with the this and super references?
a.The new operator
b.The instanceof operator
c.The dot operator
Ans: c.

34) A constructor is automatically called when an object is instantiated
a. true
b. false
Ans: a.

35) When may a constructor be called without specifying arguments?
a. When the default constructor is not called
b. When the name of the constructor differs from that of the class
c. When there are no constructors for the class
Ans: c.

36) Each class in java can have a finalizer method
a. true
b.false
Ans: a.

37) When an object is referenced, does this mean that it has been identified by the finalizer method for garbage collection?
a.yes
b.no
Ans: b.

38) Because finalize () belongs to the java.lang.Object class, it is present in all ___.
a.objects
b.classes
c.methods
Ans: b.

39) Identify the true statements about finalization.
a.A class may have only one finalize method
b.Finalizers are mostly used with simple classes
c.Finalizer overloading is not allowed
Ans: a,c.

40) When you write finalize() method for your class, you are overriding a finalizer inherited from a super class.
a.true
b.false
Ans: a.

41) Java memory management mechanism garbage collects objects which are no longer referenced
a true
b.false
Ans: a.

42) are objects referenced by a variable candidates for garbage collection when the variable goes out of scope?
a yes
b. no
Ans: a.

43) Java's garbage collector runs as a ___ priority thread waiting for __priority threads to relinquish the processor.
a.high
b.low
Ans: a,b.

44) The garbage collector will run immediately when the system is out of memory
a.true
b.false
Ans: a.

45) You can explicitly drop a object reference by setting the value of a variable whose data type is a reference type to ___
Ans: null

46) When might your program wish to run the garbage collecter?
a. before it enters a compute-intense section of code
b. before it enters a memory-intense section of code
c. before objects are finalized
d. when it knows there will be some idle time
Ans: a,b,d

47) For externalizable objects the class is solely responsible for the external format of its contents
a.true
b.false
Ans: a

48) When an object is stored, are all of the objects that are reachable from that object stored as well?
a.true
b.false
Ans: a

49) The default__ of objects protects private and trancient data, and supports the __ of the classes
a.evolution
b.encoding
Ans: b,a.

50) Which are keywords in Java?
a) NULL
b) sizeof
c) friend
d) extends
e) synchronized
Ans : d and e

51) When must the main class and the file name coincide?
Ans :When class is declared public.

52) What are different modifiers?
Ans : public, private, protected, default, static, transient, volatile, final, abstract.

53) What are access modifiers?
Ans : public, private, protected, default.

54) What is meant by "Passing by value" and " Passing by reference"?
Ans:
  • objects – pass by reference
  • Methods - pass by value

55) Is a class a subclass of itself?
Ans : A class is a subclass itself.

56) What modifiers may be used with top-level class?
Ans : public, abstract, final.

57) What is an example of polymorphism?
1.      Inner class
2.      Anonymous classes
3.      Method overloading
4.      Method overriding

Ans : c 

No comments:

Post a Comment