Programming in JAVA.
Java Week 3: Q3
A class Shape is defined with two overloading constructors in it. Another class Test1 is partially defined which inherits the class Shape. The class Test1 should include two overloading constructors as appropriate for some object instantiation shown in main( ) method. You should define the constructors using the super class constructors. Also, override the method calculate( ) in Test1 to calculate the volume of a Shape.
PROGRAM:
double height;
Test1(double l,double h){
super(l);
height=h;
}
Test1(double l,double b,double h){
super(l,b);
height=h;
}
double calculate(){
double vol;
vol=length*breadth*height;
return vol;
}
Java Week 3: Q4
This program to exercise the call of static and non-static methods. A partial code is given defining two methods, namely sum( ) and multiply ( ). You have to call these methods to find the sum and product of two numbers. Complete the code segment as instructed.
PROGRAM:
QuestionScope qs = new QuestionScope();
System.out.println(qs.sum(n1,n2));
System.out.println(QuestionScope.multiply(n1,n2)); // As Static method can be called without object using class name.
}
Disclaimer: Here you can find all nptel assignment solutions related to CS stream.These may help you for your assignment.The answers are only for verification.You cannot copy these directly from the post(code of conduct of NPTEL).These is not 100% correct solutions.
No comments:
Post a Comment
If you have any problems related to solutions or any concept please let me know.