Menu
Topics Index
...
`

Objects


If you need explanation Read this topic

If you need Answer Take test on this topic

Objects
What will be the output of the following program?
class Demo
{
    public static void main(String[] args)
    {
        Object i = new Object() // LINE A
        {
            public int hashCode()
            {
                int a = 3, b = 5;
                return a * b; // LINE B
            }
        };
        System.out.println(i.hashCode());
    }
}

A. 15
B. Compile Error at LINE A
C. Compile Error at LINE B
D. Runtime Exception
Topic: Advanced Java Programming Concepts

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

a

Posted by Maheshwari Natarajan    2014-07-09 03:49:08


Ans is A as object is base Class and a*b returns 15 and prints

Posted by Bharath Yelchuri    2014-07-09 03:53:41


B compilation error at line A  method inside a method is not possible and scope of method is with in the block  i.hashCode is not printed

Posted by Aparna Lakshmi    2014-07-09 07:17:57


answer is A. why thise suchivation hashCode() method is user defind method. but Object class call hashCode()...

Posted by Pothuluri Venkateswarlu    2014-07-09 07:34:11


A

Posted by Harsh Singh    2014-07-09 07:58:15


15

Posted by Owais Siddiqui    2014-07-09 09:24:21


A

Posted by Mohsin Deshmukh    2014-07-09 11:14:01


15

Posted by Arul Palanisamy    2014-07-09 11:40:44


A

Posted by Kisa Zahra    2014-07-09 15:52:50


A anonamus class concept  anmus class extends the object class which has hashcode method that is override in anomus class which is a class that doesn't have name it has a strong "has a" relation this type of anomus class is used in cllection to imlements iterator and enumeration

Posted by Dinesh Saini    2014-07-09 18:43:39


Congratulations Pothuluri Venkateswarlu. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-07-10 04:29:33


A

Posted by Bhuvaneswari Bhuvana    2014-07-10 13:33:49


© meritcampus 2019

All Rights Reserved.

Open In App