Premium

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



Question : Which two modifications,
made independently, enable the code to compile?

A. Make the method at line n1 public.
B. Make the method at line n2 public.
C. Make the method at line n3 public.
D. Make the method at line n3 protected.
E. Make the method at line n4 public.

 :  Which two modifications,
1. A,B

2. B,C

3. C,D

4. D,E

Correct Answer : 3
Explanation:








Question : What is the name of the Java concept that uses access modifiers to protect variables and hide
them within a class?

 :  What is the name of the Java concept that uses access modifiers to protect variables and hide
1. Encapsulation

2. Inheritance
3. Abstraction
4. Instantiation
5. Polymorphism


Correct Answer : 1
Explanation: Using the private modifier is the main way that an object encapsulates itself and hide data from the
outside world.




Question : Given the code fragment:

public static void main(String[] args){
short s1 = 200;
Integer s2 = 400;
Long s3 = (long) s1+s2; //line n1
String s4 = (String)(s3*s2); //line n2
System.out.println("Sum is " + s4);

}

What is the result?

 :  Given the code fragment:
1. Sum is 600
2. Compilation fails at line n1.
3. Compilation fails at line n2.
4. A ClassCastException is thrown at line n1.
5. A ClassCastException is thrown at line n2.




Correct Answer : 5



Related Questions


Question : You have been given code as shown.

Which option represents the state of the num array
after successful completion of the outer loop?
  : You have been given code as shown.
1. num[0][0]=10
num[0][1]=10
num[0][2]=10

2. num[0][0]=10
num[1][0]=10
num[2][0]=10
3. Access Mostly Uused Products by 50000+ Subscribers
num[0][1]=0
num[0][2]=0
4. num[0][0]=10
num[1][0]=0
num[2][0]=0




Question : You have been given a class as shown.
What would be the result if it is compiled/run

  : You have been given a class as shown.
1. Jaya25
Venkat52
2. Compilation fails only at line n1
C. Compilation fails only at line n2
3. Access Mostly Uused Products by 50000+ Subscribers

4. Compilation fails only at line n2






Question : Given the following code for a, what is the output?
 : Given the following code for a, what is the output?
1. [LQ59.HadoopExamApp;@2a139a55
Q59.HadoopExamApp.Moon@15db9742

2. [LQ59.HadoopExamApp;@2a139a55
Q59.HadoopExamApp@15db9742

3. Access Mostly Uused Products by 50000+ Subscribers
Q59.Moon@15db9742

4. Runtime Error





Question : You are asked to develop a program for a shopping application, and you are given the following information:
The application must contain the classes Toy, EduToy, and consToy. The Toy class is the superclass of the other two classes.

The
int caicuiatePrice (Toy t)
method calculates the price of a toy.

The void printToy (Toy t)
method prints the details of a toy.

Which definition of the Toy class adds a valid layer of abstraction to the class hierarchy?
 : You are asked to develop a program for a shopping application, and you are given the following information:
1.
public abstract class Toy{
public abstreact int caicuiatePrice (Toy t) ;
void printToy (Toy t) {/*code goes here*/}
}

2.
public abstract class Toy{
public int caicuiatePrice (Toy t) ;
void printToy (Toy t);
}
3. Access Mostly Uused Products by 50000+ Subscribers
public abstract class Toy{
public int caicuiatePrice (Toy t) ;
public final void printToy (Toy t) {/*code goes here*/}
}

4.
public abstract class Toy{
public abstract int caicuiatePrice(Toy t){/*Code goes here*/} ;
void printToy (Toy t){/*Code goes here*/};
}





Question : You have been given following code

public static void main(String[] args) {
int[] intArr = {15,30,45,60,75};
intArr[2] = intArr[4];
intArr[4] = 90;

for (int i = 0; i < intArr.length; i++) {
System.out.print(intArr[i] + ", ");
}
}

After executing this code, what would be printed

 : You have been given following code
1. 15, 60, 45, 90, 75,
2. 15, 90, 45, 90, 75,
3. Access Mostly Uused Products by 50000+ Subscribers
4. 15, 30, 90, 60, 90,
5. 15, 4, 45, 60, 90,



Question : You have been given following arrays

int[] intArr = {8,16,32,64,128};

which two code fragements , independently , print each element in this array?

A. for(int i : intArr){
System.out.print(intArr[i] + ", ");
}

B. for(int i : intArr){
System.out.print(i + ", ");
}

C. for(int i=0 : intArr){
System.out.print(intArr[i] + ", ");
i++;
}

D. for(int i=0 ; i System.out.print(i + " ");
}

E. for(int i=0 ; i System.out.print(intArr[i] + " ");
}

F. for(int i; i System.out.print(intArr[i] + " ");
}

 : You have been given following arrays
1. A,B
2. C,D
3. Access Mostly Uused Products by 50000+ Subscribers
4. E,F
5. B,E