Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace inharitance_week7
- {
- public partial class Form1 : Form
- {
- // membuat clas inti dari button clas - clas tersebut bisa digunkaan oleh semua buton
- class cmath
- {
- public int Tambah (int a , int b)
- {
- return a + b;
- }
- public int kurang (int a, int b)
- {
- return a - b;
- }
- }
- class cmath2 : cmath
- {
- public int kali (int a , int b)
- {
- return a * b;
- }
- public int bagi (int a , int b)
- {
- return a / b;
- }
- }
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- cmath vcmath = new cmath();
- int vhasil;
- vhasil = vcmath.Tambah(1, 2);
- MessageBox.Show(vhasil.ToString());
- }
- private void button2_Click(object sender, EventArgs e)
- {
- cmath2 vcmath2 = new cmath2();
- int vhasil;
- vhasil = vcmath2.Tambah(1, 2);
- MessageBox.Show(vhasil.ToString());
- }
- }
- }
- # 2
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- class Program
- {
- class Animal
- {
- public string name;
- public int age;
- public float happines;
- public void printBase()
- { Console.WriteLine("Name " + name);
- Console.WriteLine("Age" + age);
- Console.WriteLine("Happines" + happines);
- }
- }
- class dog : Animal
- {
- public int spotCount;
- public void bark ()
- {
- Console.WriteLine("wuf");
- base.happines += 0.1f;
- }
- }
- class cat : Animal
- {
- public float cuteness;
- public void meaw ()
- {
- Console.WriteLine("meaw");
- }
- }
- static void Main(string[] args)
- {
- dog spooty = new dog();
- spooty.name = "spotty";
- spooty.age = 4;
- spooty.happines = 0.8f;
- spooty.spotCount = 25;
- spooty.printBase();
- spooty.bark();
- Console.WriteLine("New Happines : " + spooty.happines);
- Console.WriteLine();
- cat heisenberg = new cat();
- heisenberg.name = "Heisenberg";
- heisenberg.age = 13;
- heisenberg.happines = 0.3f;
- heisenberg.cuteness = 0.4f;
- heisenberg.printBase();
- heisenberg.meaw();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement