Estensioni Metodi Classi java
3 File
Main.java
A.java
B.java
Main.java
package a;
/**
*
* @author dellxps
*/
public class Main {
public static void main(String[] args) {
try
{
A a=new A();
a.print();
B b=new B();
b.print();
}
catch (Exception e)
{
}
}
}
A.java
public class A {
public void print() {
String[] data = { "\u250C\u2500\u2500\u2500\u2500\u2500\u2510",
"\u2502Hello\u2502",
"\u2514\u2500\u2500\u2500\u2500\u2500\u2518" };
try
{
for (String s : data) {
System.out.println(s);
}
for (String s : data) {
System.console().writer().println(s);
}
}
catch (Exception e)
{
}
}
}
B.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
// http://stackoverflow.com/questions/4188091/java-extends-example
package a ;
/**
*
* @author dellxps
*/
public class B extends A {
private String out2 = "child";
@Override
public void print(){
System.out.println(out2);
}
}
Output
run:
┌─────┐
│Hello │
└─────┘
child
BUILD SUCCESSFUL (total time: 0 seconds)