Home »
MCQs »
Perl Programming MCQs
What will be the output of the following Perl code?
16. What will be the output of the following Perl code?
use strict;
use warnings;
package vehicle;
sub set_mileage{
my $class = shift;
my $self = {
'distance'=> shift,
'petrol_consumed'=> shift
};
bless $self, $class;
return $self;
}
sub get_mileage{
my $self = shift;
my $result = $self->{'distance'} / $self->{'petrol_consumed'};
print "$result\n";
}
my $ob1 = vehicle -> set_mileage(2550, 175);
$ob1->get_mileage();
- 15
- 15.00
- 14.5714285714286
- None of these
Answer: C) 14.5714285714286