Добавил:
Upload
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package laba2;
/**
*
* @author st
*/
import java.util.Scanner;
import java.io.*; // подключение библиотеки ввода-вывода на java
import java.lang.Math.*;
class Record //****Class Кошелёк
{
protected int first;
protected double second;
public void Init(int f,double s)
{
first=f;
second=s;
}
public double Summa()
{
return first*second;
}
public int GetFirst()
{
return first;
}
public double GetSecond()
{
return second;
}
}
class Sprint extends Record // extends наследует (расширяет) – это подкласс
{
private int dec;
public void Putdec(int d)
{
dec=d;
}
public double Summa()
{
double k;
k=first*second;
return k+dec;
}
}
public class Laba2{
public static void main (String args[] )
{
double p;
Record a=new Record(); // объект Record
a.Init(2, 40);
p=a.Summa();
System.out.printf("%f\n ", p);
Sprint b=new Sprint(); // объект Sprint
b.Init(1, 10); // вызов наследуемого метода;
b.Putdec(6);
p=b.Summa();
System.out.printf("%f\n ", p);
}
}
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package laba2;
/**
*
* @author st
*/
import java.util.Scanner;
import java.io.*; // подключение библиотеки ввода-вывода на java
import java.lang.Math.*;
class Record //****Class Кошелёк
{
protected int first;
protected double second;
public void Init(int f,double s)
{
first=f;
second=s;
}
public double Summa()
{
return first*second;
}
public int GetFirst()
{
return first;
}
public double GetSecond()
{
return second;
}
}
class Sprint extends Record // extends наследует (расширяет) – это подкласс
{
private int dec;
public void Putdec(int d)
{
dec=d;
}
public double Summa()
{
double k;
k=first*second;
return k+dec;
}
}
public class Laba2{
public static void main (String args[] )
{
double p;
Record a=new Record(); // объект Record
a.Init(2, 40);
p=a.Summa();
System.out.printf("%f\n ", p);
Sprint b=new Sprint(); // объект Sprint
b.Init(1, 10); // вызов наследуемого метода;
b.Putdec(6);
p=b.Summa();
System.out.printf("%f\n ", p);
}
}