Premium

Oracle Java Programming Certification Questions and Answers (Dumps and Practice Questions)



Question : : Which statement best describes encapsulation?
 :  : 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?

 :   Given the code fragment:
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?
 :  Given:
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.


Related Questions


Question : Which statement is true about the default constructor of a top-level class?

 :  Which statement is true about the default constructor of a top-level class?
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.




Question : You have been given below code

List colors = new ArrayList();
colors.add("green");
colors.add("red");
colors.add("blue");
colors.add("yellow");
colors.remove(2);
colors.add(3, "cyan");
System.out.print(colors);


 : You have been given below code
1. [green, red, yellow, cyan]
2. [green, blue, yellow, cyan]
3. Access Mostly Uused Products by 50000+ Subscribers
4. An IndexoutofBoundsException is thrown at runtime






Question : The catch clause argument is always of type .

A. Exception
B. Exception but NoT including RuntimeException
C. Throwable
D. RuntimeException
E. CheckedException


 : The catch clause argument is always of type .
1. A
2. B
3. Access Mostly Uused Products by 50000+ Subscribers
4. D
5. E





Question : You have been given following code

public class MainMethod {
void main() {
System.out.println("one");
}

static void main(String args) {
System.out.println("two");
}

public static void main(String[] args) {
System.out.println("three");
}

void mina(object[] args) {
System.out.println("four");
}
}

What is printed out when the program is excuted?

 : You have been given following code
1. one
2. two
3. Access Mostly Uused Products by 50000+ Subscribers
4. four




Question : You have been given following code

int var1 = -5;
int var2 = var1--;
int var3 = 0;
if (var2 <lt; 0) {
var3 = var2++;
} else {
var3 = --var2;
}
System.out.println(var3);

What is the result?


 : You have been given following code
1. -6
2. -4
3. Access Mostly Uused Products by 50000+ Subscribers
4. 5

5. 4




Question : You have been given below code

public class FieldInit {
char c;
boolean b;
float f;

void printAll() {
System.out.println("c = " + c);
System.out.println("c = " + b);
System.out.println("c = " + f);
}

public static void main(String[] args) {
FieldInit f = new FieldInit();
f.printAll();
}
}

What would be result ?

 : You have been given below code
1. c = null
b = false
f = 0.0F
2. c = 0
b = false
f = 0.0f
3. Access Mostly Uused Products by 50000+ Subscribers
b = true
f = 0.0
4. c =
b = false
f = 0.0