It is easy to put an object in one object but when I line 36: at aclass.getInfo (3) I try to do the methods;
I can not find a symbol
and can not compile. How do I use a class in an object? The objective is to use Class A or Classbie, which depends on some int or something else.
Package testing; Public Sector Exams {Object Eccles; Public interface iphone {zero getInfo (int i); } Public class class A infusel {@Override applies the public zero getInfo (int i) {System.out.println ("class:" + this.getClass () + "" + i); }} Public Class Classby Inflation Information {@Override Public Zero getInfo (int i) {System.out.println ("Classbie:" + this.getClass () + "" + i); }} Public Zero Testing Class () {Class A Test A = New Class (); Class B Test B = New Classby (); TestA.getInfo (1); TestB.getInfo (2); Int i = 1; If (i == 1) {aClass = testA; } And {aClass = testB; } System.out.println ("aclass:" + aclass.getClass ()); // aclass.getInfo (3); } Public static zero main (string [] args) {test test = new test (); Test.testClass (); Because} aclass
only classes
or
classbie
, which are both subtypes of InFace
, you can change the object aclass ;
to
FLS Alas; After that, your
type of variable will support a method, calledInFace getInfo (int i)
and your Code will be compiled.
No comments:
Post a Comment