Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
TDD for a Shopping Website LiveProject
this week in the
Testing
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Paul Clapham
Ron McLeod
Jeanne Boyarsky
Tim Cooke
Sheriffs:
Liutauras Vilda
paul wheaton
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Carey Brown
Frits Walraven
Bartenders:
Piet Souris
Himai Minh
Forum:
Programmer Certification (OCPJP)
OOPs Concept (Over-riding)
Nishant Hadole
Greenhorn
Posts: 4
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The output of code below is "Sachin" and not "Nishant", just need explanation for the same...
class BaseClass{
protected
String
name="Sachin";
public void printName(){
System.out.println(name);
}
}
public class MyClass extends BaseClass{
private String name="Nishant";
public static void main(String[] args){
MyClass myClassObj = new MyClass();
myClassObj.printName();
}
}
Deepak Bala
Bartender
Posts: 6663
5
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hint: Try overriding the method.
Also please use code tags when you display code in a POST
SCJP 6 articles
-
SCJP 5/6 mock exams
-
More SCJP Mocks
Jesper de Jong
Java Cowboy
Posts: 16084
88
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Note that member
variables
cannot be overridden. Only methods can be overridden.
Jesper's Blog
-
Pluralsight Author Page
Rakesh Chaudhary
Ranch Hand
Posts: 120
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hope this helps...
class BaseClass
{
protected String name="Sachin";
public void printName()
{
System.out.println(name);
}
}
public class MyClass extends BaseClass
{
private String name="Nishant";
public void printName()
{
System.out.println(name);
}
public static void main(String[] args){
BaseClass myClassObj = new MyClass();
myClassObj.printName();
}
}
Byee....
How do they get the deer to cross at the signs? Or to read this tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Constructor & Polymorphism
multiple casting
Superclass has subclass reference
Java Generics Problem
an parent object's lock
More...