public class HelloWorld extends A {
String b = "HelloWorld";
public static void main(String []args){
HelloWorld helloWorld = new HelloWorld();
helloWorld.bb();
}
}
class A {
public void bb(){
System.out.println(b);
}
}
To print println(b)
in class A
by referring to String b="HelloWorld"
in class HelloWorld
How do I modify or write an expression?
public class HelloWorld extensions A{
String b = "HelloWorld";
public static void main(String []args){
A Class = new A();
Class.bb();
}
}
class A {
public void bb(){
HelloWorld helloWorld = new HelloWorld();
System.out.println(helloWorld.b)b);
}
}
It would be convenient to use static variables, but if you want to generate objects and output them as references, create HelloWorld objects in class A and use HelloWorld, a reference variable created by an object when printingln.Put the value in b. After that, if you create class A as an object in the main and call the bb method, it will be printed. In fact, if you code like this, you don't have to inherit it.
© 2024 OneMinuteCode. All rights reserved.