Inheritance
Ineritance
A mechanism to settle state and beahviour from the superclass to the subclass.
Inheritance offers a concept reused in the development of software.
Program development segitga class
triangle program
(class Segitiga
protected int base;
protected int level;
void setAlas (int newValue) (
base = newValue;
)
void setTinggi (int newValue) (
high = newValue;
)
double getLuas () (
return 0.5 * base * high;
)
)
Program SegitigaKaki inherit a program segititga
SegitigaKaki Segitiga class extends (
double getKeliling () (
return base + Math.sqrt (0.5 * base * base + * high-high);
)
)
Program hitungSegitigaKaki
import java.io. *;
(class hitungSegitigaKaki
public static void main (String [] args) (
A triangle Segitiga = new ();
SegitigaKaki b = new SegitigaKaki ();
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
int temp;
System.out.print ( "Length of base:");
try (
temp = Integer.parseInt (br.readLine ());
a.setAlas (temp);
b.setAlas (temp);
) Catch (IOException e) ()
System.out.print ( "Height:");
try (
temp = Integer.parseInt (br.readLine ());
a.setTinggi (temp);
b.setTinggi (temp);
) Catch (IOException e) ()
System.out.println ( "Area is:" + a.getLuas ());
System.out.println ( "circumference is:" + b.getKeliling ());
)
)
0 komentar
:)) :)] ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* : 8-} ~x( :-t b-( :-L x( =))
Posting Komentar