Question : : Which statement best describes encapsulation? 1. Encapsulation ensures that classes can be designed so that only certain fields and methods of an object are accessible from other objects. 2. Encapsulation ensures that classes can be designed so that their methods are inheritable. 3. Encapsulation ensures that classes can be designed with some fields and methods declared as abstract. 4. Encapsulation ensures that classes can be designed so that if a method has an argument MyType x, any subclass of MyType can be passed to that method.
Correct Answer : 1
Explanation: Encapsulation ensures that classes can be designed so that only certain fields and methods of an object are accessible from other objects.
Question : Given the code fragment:
int a[] = {1,2,3,4,5};
for(XXX){ System.out.print(a[e]); }
Which option can replace xxx to enable the code to print 24?
1. int e = 0; e<=4; e++ 2. int e = 1; e<5; e+=2 3. int e = 1; e<=5; e+=1 4. int e = 1; e<5; e+=2
Correct Answer : 2
Explanation: In this case we need to have print 24 (which is alternate digit or you can say counter incremented by 2 and starting with 2nd position). Best suitable answer in this case is option 2.
Question : Given:
And given code fragment :
DVD dvd = new DVD(10,20)
Which code fragment should you use at line n1 to instantiate the dvd object successfully? 1. super.r =r; this.c = c; 2. super(r); this(c); 3. super(r); this.c = c;
4. this.c=r; super(c);
Correct Answer : 3
Explanation: In subclass constructor your first statement should be call to a super class constructor. Which can be implemented using super(r) . This will call super class constructor with the super(r) which has single argument.
1. It can take arguments. 2. It has private access modifier in its declaration. 3. Access Mostly Uused Products by 50000+ Subscribers 4. The default constructor of a subclass always invokes the no-argument constructor of its superclass.