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();
  1. 15
  2. 15.00
  3. 14.5714285714286
  4. None of these

Answer: C) 14.5714285714286

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.