Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace inharitance_week7
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         // membuat clas inti dari button clas - clas tersebut bisa digunkaan oleh semua buton
  16.         class cmath
  17.         {
  18.             public int Tambah (int a , int b)
  19.             {
  20.                 return a + b;
  21.             }
  22.             public int kurang (int a, int b)
  23.             {
  24.                 return a - b;
  25.             }
  26.         }
  27.         class cmath2 : cmath
  28.         {
  29.             public int kali (int a , int b)
  30.             {
  31.                 return a * b;
  32.             }
  33.             public int bagi (int a , int b)
  34.             {
  35.                 return a / b;
  36.             }
  37.         }
  38.         public Form1()
  39.         {
  40.             InitializeComponent();
  41.         }
  42.  
  43.         private void button1_Click(object sender, EventArgs e)
  44.         {
  45.             cmath vcmath = new cmath();
  46.             int vhasil;
  47.             vhasil = vcmath.Tambah(1, 2);
  48.             MessageBox.Show(vhasil.ToString());
  49.         }
  50.  
  51.         private void button2_Click(object sender, EventArgs e)
  52.         {
  53.             cmath2 vcmath2 = new cmath2();
  54.             int vhasil;
  55.             vhasil = vcmath2.Tambah(1, 2);
  56.             MessageBox.Show(vhasil.ToString());
  57.         }
  58.     }
  59. }
  60.  
  61.  
  62. # 2
  63. using System;
  64. using System.Collections.Generic;
  65. using System.Linq;
  66. using System.Text;
  67. using System.Threading.Tasks;
  68.  
  69. namespace ConsoleApplication1
  70. {
  71.     class Program
  72.     {
  73.         class Animal
  74.         {
  75.             public string name;
  76.             public int age;
  77.             public float happines;
  78.  
  79.             public void printBase()
  80.  
  81.             { Console.WriteLine("Name " + name);
  82.                 Console.WriteLine("Age" + age);
  83.                 Console.WriteLine("Happines" + happines);
  84.             }
  85.         }
  86.  
  87.         class dog : Animal
  88.         {
  89.             public int spotCount;
  90.  
  91.             public void bark ()
  92.             {
  93.                 Console.WriteLine("wuf");
  94.                 base.happines += 0.1f;
  95.             }
  96.         }
  97.  
  98.          class cat : Animal
  99.         {
  100.             public float cuteness;
  101.  
  102.             public void meaw ()
  103.             {
  104.                 Console.WriteLine("meaw");
  105.             }
  106.         }
  107.         static void Main(string[] args)
  108.         {
  109.             dog spooty = new dog();
  110.             spooty.name = "spotty";
  111.             spooty.age = 4;
  112.             spooty.happines = 0.8f;
  113.             spooty.spotCount = 25;
  114.             spooty.printBase();
  115.             spooty.bark();
  116.  
  117.             Console.WriteLine("New Happines : " + spooty.happines);
  118.  
  119.             Console.WriteLine();
  120.  
  121.             cat heisenberg = new cat();
  122.             heisenberg.name = "Heisenberg";
  123.             heisenberg.age = 13;
  124.             heisenberg.happines = 0.3f;
  125.             heisenberg.cuteness = 0.4f;
  126.             heisenberg.printBase();
  127.             heisenberg.meaw();
  128.  
  129.             Console.ReadKey();
  130.         }
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement