One.java
------------
public class One{
int x;
char y;
One(){x=0;y='a' ;}
public void disp(){System.o ut.println("x ="+x+", y ="+y);}
}
OneX.java
---------------
public class OneX extends One{
double z;
OneX(){z=1.05;}
public void dispX(){System. out.println("z ="+z);}
public static void main(String[] aa){
One obj1;
obj1=new OneX();
obj1.dispX();
}
}
When I compile the OneX.java file
then
OneX.java: cannot resolve symbol
symbol : method dispX ()
location: class One
obj1.dispX();
5 1456 Laharl 849
Recognized Expert Contributor
Your issue here is that obj1 is defined to be an object of type One, not OneX. obj1 only knows about the methods of One, not those of OneX, because even though it's set to a OneX object, it's still treated by the compiler as a One object. I know that explanation's not all that great, if you don't get it just let me know and I'll try again...
Your issue here is that obj1 is defined to be an object of type One, not OneX. obj1 only knows about the methods of One, not those of OneX, because even though it's set to a OneX object, it's still treated by the compiler as a One object. I know that explanation's not all that great, if you don't get it just let me know and I'll try again...
I think that obj1 has memory of object of OneX. therefore it should has methods and fields of object of OneX.
Thanks for answer, Please clerify me more. this is very helpful me.
JosAH 11,448
Recognized Expert MVP
You told your compiler that your obj1 is a One object. Such an object doesn't
have a dispX() method. The fact that you sneakily assigned an ObjX object to
obj1 doesn't count for the compiler, i.e. your obj1 is a One object.
kind regards,
Jos
Please put your code in code tags. It makes it much easier to read. To put your code in code tags when you are creating a new messsge click on the # sign. Type or paste your cod then click the # sign again.
JosAH 11,448
Recognized Expert MVP
Please put your code in code tags. It makes it much easier to read. To put your code in code tags when you are creating a new messsge click on the # sign. Type or paste your cod then click the # sign again.
# that doesn't seem to work for me ... #
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jan Pieter Kunst |
last post by:
(apologies if this message is a duplicate -- my news server seems to
have problems)
Greetings,
When using PHP 4, this:
// ex. 1
class A {
function A(&$obj) {
|
by: jon wayne |
last post by:
OK!
I had this nagging doubt
Consider (without worrying abt access specifiers)
class Kid : public Parent{...};
Parent::someFunc()
{
Kid k;
}
|
by: ad |
last post by:
I think we always new a class like below:ClassName1 OjbectName=new
ClassName1();But I find some example codes which new a class with different
classClassName1 OjbectName=new ClassName2();What is the purpose to do so?
|
by: M Shafaat |
last post by:
Hi!
Consider the following:
Object A is a member of Object B.
Object A has a known identifier.
Object B has an unknown identifier.
How do we reference Object B using Object A?
I have tried using "owner", "container", "parent", etc. without success.
Please help.
|
by: Crirus |
last post by:
I have this classes tree
GameManager 1 object
Game Multiple objects
Map 1 object
Player Multiple objects
Squads Multiple objects
Units Multiple objects
Now each Squad or Units have to know about data on it's Map
| |
by: LCAdeveloper |
last post by:
Can anyone help me with this? I'm trying to get an MDIChild form to lookup
the value of a control on another open MDIChild form, but can't seem to get
the right syntax.
Let's say the two child forms are Form1 and Form2. In VB4 I could use (in
Form2):
\\
If Form1.Option1.Value = True Then
//
|
by: Sean Dockery |
last post by:
I have the following HTML file that I've been using for testing...
<html>
<head>
<script type="text/javascript">
<!--
function handleWindowLoad() {
var items = ;
for (var i = 0; i < 11; i++) {
items = "item" + (i + 1);
|
by: Bryan Parkoff |
last post by:
I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline. I define variables and functions in the global scope. The global
variables and global functions are hidden to prevent from accessing by the
programmers. All global functions share global variables.
Only very few global functions are allowed to be reusability for the
programmers to use. Few...
|
by: raylopez99 |
last post by:
Keywords: scope resolution, passing classes between parent and child
forms, parameter constructor method, normal constructor, default
constructor, forward reference, sharing classes between forms.
Here is a newbie mistake that I found myself doing (as a newbie), and
that even a master programmer, the guru of this forum, Jon Skeet,
missed! (He knows this I'm sure, but just didn't think this was my
problem; LOL, I am needling him)
If...
|
by: HoangTuanSu |
last post by:
I have just got a javascript code from my friend. I've modified it for my purpose but a problem happens. First, here's my code
html
<body>
<table align="center" width="60%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr height="100">
<td width="20%" height="114">abc</td>
<td width="80%">def</td>
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |