About Question enthuware.ocpjp.v11.2.1890 :

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

Moderator: admin

Post Reply
stanmak
Posts: 1
Joined: Sun Jun 06, 2021 2:15 pm
Contact:

About Question enthuware.ocpjp.v11.2.1890 :

Post by stanmak »

class Baap {
public int h = 4;

public int getH() {
System.out.println("Baap " + h);
return 5;
}
}

public class Main2 extends Baap {
public int h = 44;

public int getH() {
System.out.println("Beta " + h);
return h;
}


public static void main(String[] args) {
Main2 b = new Main2();
System.out.println(b.h + " " + b.getH());
Main2 bb = (Main2) b;
System.out.println(bb.h + " " + bb.getH()); }

}
//output
Beta 44
44 44
Beta 44
44 44

//Question
I dont understand why it System.out.println(b.h + " " + b.getH()); didtnt print 44 Beta 44 . I think b.h should have resulted to 44. Then b.getH prints Beta then 44 so that we have 44 Beta 44 as opposed to Beta 44

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

Re: About Question enthuware.ocpjp.v11.2.1890 :

Post by admin »

Explained in this thread viewtopic.php?f=2&t=2075
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 2 guests