Total Pageviews

Sunday, May 25, 2014

OCJP - Oracle Certified Java Professional - Java Questions - 1

OCJP - Java Questions - 1

What is the output for the below code ?

1. public class A {
2. int add(int i, int j){
3. return i+j;
4. }
6.public class B extends A{
7. public static void main(String argv[]){
8. short s = 9;
9. System.out.println(add(s,6));
10. }
Options are
A.Compile fail due to error on line no 2
B.Compile fail due to error on line no 9
C.Compile fail due to error on line no 8
Answer :
B is the correct answer.
Cannot make a static reference to the non-static method add(int, int) from the type A. The
short s is autoboxed correctly, but the add() method cannot be invoked from a static
method because add() method is not static

For further details of JAVA Training / OCJP Certification contact:

Placement opportunities are given for successful student who passes OCJP Certification in JAVA Software Development in Software companies

SUGA JAVA Training Institute,
SUGA Employment Services (providing placement opportunities for those who finish OCJP Certification through our JAVA Training)
(A division of SUGA Consulting Services)
Office No.26, TNHB Complex,
180, Luz Church Road, Mylapore, Chennai - 600004

N.Sugavanam, M.A., F.I.I.I, MBA,  
CEO, SUGA Consulting Services

Phone: Vodafone: 91762-44989, Landline: 044-2498-4149

Landmark: Near Luz Signal, Luz Pillaiyar Koil, behind 'MAX' Show Room

1 comment:

  1. Amazing Article, thank you!. I am very glad to read your informative & practical blog. Kindly keep updating your blog.
    Java Developer is a wonderful career for IT students.To start Dream Career to become a Java developer learn from
    Java Training in Chennai
    . or learn thru Java Online Training from India .