About Question enthuware.ocpjp.v17.2.2016 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
tsmanic
Posts: 1
Joined: Wed Mar 08, 2023 1:47 am
Contact:

About Question enthuware.ocpjp.v17.2.2016 :

Post by tsmanic »

Does any one understand this. Specifically what is happening on Line 1. Can you within a class make the type the class? In class Y can the variable val be of type Y?



Identify correct statement about the following code -

Code: Select all

class X{
int val = 10;
}

class Y extends X{
Y val = null; //1
}

public class TestClass extends X{

  public static void main(String[] args){
    Y y = new Y();
    int k = (X) y.val ; //2
    System.out.println(k);

  }
}
the code will actually not compile due to line 2 from the explanation.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v17.2.2016 :

Post by admin »

What happened when you tried it out? Remove line 2 and see whether you can have the variable val be of type Y inside Y.

Hint: How do linked lists work?
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 38 guests