Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What will be the output of the following piece of code?

 
Sivapraveen Chandana
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Clidder {
private final void flipper(){ System.out.println("Clidder"); }
}

public class Clidlet extends Clidder {
public final void flipper(){System.out.println("Clidlet"); }
public static void main(String [] args) {
Clidder c = new Clidlet();
c.flipper();
}
}




thanks in advance..
[ January 08, 2008: Message edited by: Sivapraveen Chandana ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why ask people to tell you, when you could simply compile and run it?

This is obviously an SCJP question, so I'll move this to the appropriate forum.
 
Arjun Cheng
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not going to run.
 
Dean Jones
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code won't go past the compiler, as in the subclass you are trying to call a private method of the superclass, which is not visible.
[ January 08, 2008: Message edited by: Dean Jones ]
 
Raghu Doppalapudi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If the code is as above works fine and prints clidlet.
In the code you posted you are trying to access private method which is not visible.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic