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
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
Object and String
sanjana narayanan
Ranch Hand
Posts: 142
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
This question is from a mock exam.
Object o = new
String
("abcd"); //1
System.out.println(o);
It gives an error at line 1. But in my opinion, Object is a superclass and String is a subclass. Then why is line #1 is erroneous?
-Sanjana
Siva kandasamy
Ranch Hand
Posts: 139
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Sanjana,
I don't see any problem. See my code bwlow. It is working.
class Seed { Object o = new String("ABCD"); } class Test { public static void main( String[] args){ Seed s = new Seed(); System.out.println(s.o); } }
sanjana narayanan
Ranch Hand
Posts: 142
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks..I realised that I made a silly mistake in the code.
-Sanjana
ice is for people that are not already cool. Chill with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
when is eligible for garbage collection?
How many String objects ... ?!
Casting in java
GC doubt
casting an object array
More...