Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Harjoituskoe
- {
- class Program //tehtävä 2
- {
- static void Main(string[] args)
- {
- int nopeus = 100;
- Auto lada = new Auto(130);
- kuormaauto scania = new kuormaauto(110, 15);
- if (scania.asetanopeus(nopeus)) Console.WriteLine("onnistui");
- if (lada.asetanopeus(nopeus)) Console.WriteLine("onnistui");
- scania.tiedot();
- lada.tiedot();
- }
- }
- }
- //______________________________
- namespace Harjoituskoe
- {
- class Auto
- {
- int x = 0;
- int y = 0;
- public Auto(int maxnopeus)
- {
- x = maxnopeus;
- }
- public bool asetanopeus(int nopeus)
- {
- if (y < x)
- {
- y = nopeus;
- } return true;
- }
- public virtual void tiedot()
- {
- Console.WriteLine("Auto");
- Console.WriteLine("Max nopeus"+x);
- Console.WriteLine("Nopeus" + y);
- }
- }
- }
- //___________________________________
- namespace Harjoituskoe
- {
- class kuormaauto:Auto
- {
- int z;
- public kuormaauto(int x, int y)
- : base(maxnopeus)
- {
- }
- public override void tiedot()
- {
- Console.WriteLine("Kuormaauto");
- Console.WriteLine("Lastauskyky"+z);
- base.tiedot();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment