<< Chapter < Page Chapter >> Page >
class A extends Base implements X{ public void inherMethod(){System.out.print( " A-inherMethod ");}//end inherMethod()public void intfcMethodX(){ System.out.print("A-intfcMethodX "); }//end intfcMethodX()}//end class A class B extends Base implements X{public void inherMethod(){ System.out.print(" B-inherMethod "); }//end inherMethod()public void intfcMethodX(){System.out.print("B-intfcMethodX "); }//end intfcMethodX()}//end class B

Concrete definitions of the interface method

As before, these methods provide concrete definitions of the method named intfcMethodX , which is declared in the interface named X .

An array of references of type Object

The interesting portion of this program begins in the following fragment, which instantiates and populates a two-element array object (container) of type Object . (In the sense of this discussion, an array object is a container, albeit a very simple one.)

void doIt(){ Object[]myArray = new Object[2];myArray[0] = new A();myArray[1] = new B();

Store object references of type A and B as type Object

Because the container is declared to be of type Object , references to objects instantiated from any class can be stored in the container. The code in theabove fragment instantiates two objects, (one of class A and the other of class B ), and stores the two object's references in the container.

Cannot call interface method as type Object

The code in the for loop in the next fragment attempts to call the method named intfcMethodX on each of the two objects whose references are stored in the elements of the array.

for(int i=0;i<myArray.length;i++){ myArray[i].intfcMethodX(); }//end for loopSystem.out.println(""); }//end doIt()

This produces the following compiler error under JDK 1.3:

Ap136.java:24: cannot resolve symbol symbol : method intfcMethodX ()location: class java.lang.ObjectmyArray[i].intfcMethodX();

What methods can you call as type Object?

It is allowable to store the reference to an object instantiated from any class in a container of the type Object . However, the only methods that can be directly called (without a cast and not using generics) on that reference are the following eleven methods. These methods are defined in the class named Object :

  • clone ()
  • equals(Object obj)
  • finalize()
  • getClass()
  • hashCode()
  • notify()
  • notifyAll()
  • toString()
  • wait()
  • wait(long timeout)
  • wait(long timeout,int nanos)

Overridden methods

Some, (but not all) , of the methods in the above list are defined with default behavior in the Object class, and are meant to be overridden in new classes that you define. This includes the methods named equals and toString .

Some of the methods in the above list, such as getClass , are simply utility methods, which are not meant to be overridden.

Polymorphic behavior applies

If you call one of these methods on an object's reference (being stored as type Object) , polymorphic behavior will apply. The version of the method overridden in, or inherited into, the class from which the object wasinstantiated will be identified and executed.

Questions & Answers

so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
how to fabricate graphene ink ?
SUYASH Reply
for screen printed electrodes ?
SUYASH
What is lattice structure?
s. Reply
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
Sanket Reply
what's the easiest and fastest way to the synthesize AgNP?
Damian Reply
China
Cied
types of nano material
abeetha Reply
I start with an easy one. carbon nanotubes woven into a long filament like a string
Porter
many many of nanotubes
Porter
what is the k.e before it land
Yasmin
what is the function of carbon nanotubes?
Cesar
I'm interested in nanotube
Uday
what is nanomaterials​ and their applications of sensors.
Ramkumar Reply
what is nano technology
Sravani Reply
what is system testing?
AMJAD
preparation of nanomaterial
Victor Reply
Yes, Nanotechnology has a very fast field of applications and their is always something new to do with it...
Himanshu Reply
good afternoon madam
AMJAD
what is system testing
AMJAD
what is the application of nanotechnology?
Stotaw
In this morden time nanotechnology used in many field . 1-Electronics-manufacturad IC ,RAM,MRAM,solar panel etc 2-Helth and Medical-Nanomedicine,Drug Dilivery for cancer treatment etc 3- Atomobile -MEMS, Coating on car etc. and may other field for details you can check at Google
Azam
anybody can imagine what will be happen after 100 years from now in nano tech world
Prasenjit
after 100 year this will be not nanotechnology maybe this technology name will be change . maybe aftet 100 year . we work on electron lable practically about its properties and behaviour by the different instruments
Azam
name doesn't matter , whatever it will be change... I'm taking about effect on circumstances of the microscopic world
Prasenjit
how hard could it be to apply nanotechnology against viral infections such HIV or Ebola?
Damian
silver nanoparticles could handle the job?
Damian
not now but maybe in future only AgNP maybe any other nanomaterials
Azam
Hello
Uday
I'm interested in Nanotube
Uday
this technology will not going on for the long time , so I'm thinking about femtotechnology 10^-15
Prasenjit
can nanotechnology change the direction of the face of the world
Prasenjit Reply
At high concentrations (>0.01 M), the relation between absorptivity coefficient and absorbance is no longer linear. This is due to the electrostatic interactions between the quantum dots in close proximity. If the concentration of the solution is high, another effect that is seen is the scattering of light from the large number of quantum dots. This assumption only works at low concentrations of the analyte. Presence of stray light.
Ali Reply
the Beer law works very well for dilute solutions but fails for very high concentrations. why?
bamidele Reply
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!
QuizOver.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask