Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HelloWorld
- {
- // arguments are passed using the text field below this editor
- public static void main(String[] args)
- {
- Konto klaus = new Konto("Peter Klaus", 1337);
- System.out.println(klaus);
- klaus.einzahlen(20000);
- System.out.println(klaus);
- klaus.inhaber = "Petra Klaus";
- System.out.println(klaus);
- klaus.abheben(1500);
- System.out.println(klaus);
- /*
- Error:
- klaus.nr = 1;
- */
- try{
- klaus.kontoStand = (int) 1e6;
- }catch(Exception a){
- System.out.println("Can't change Money");
- }
- System.out.println(klaus);
- }
- public static class Konto {
- public String inhaber;
- protected int kontoStand;
- public final int nr;
- public Konto(String inhaber, int nr)
- {
- this.kontoStand = 0;
- this.inhaber = inhaber;
- this.nr = nr;
- }
- public void einzahlen(int a){
- kontoStand += a;
- }
- public void abheben(int a){
- kontoStand -= a;
- }
- public String toString()
- {
- return inhaber+" hat "+ kontoStand+" euro. Nr.: "+ nr;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement