NPTEL JAVA WEEK 02 ASSIGNMENT SOLUTION
WEEK 02 SOLUTIONS WITH PROOF OF COMPILATION.
QUESTION NO 1= Call the method print() of class Student first and then call print() method of class School?
ANSWER NO 1 =
// Create an object of class Student
Student stu = new Student();
// Call 'print()' method of class Student
stu.print();
// Create an object of class School
School sch = new School();
// Call 'print()' method of class School
sch.print();
PROOF=
QUESTION NO 2= Complete the code segment to call the method print() of class given class Printer to print the following.
--------------------------------
Hi! I am class STUDENT
Hi! I class SCHOOL.
--------------------------------?
ANSWER NO 2=
Printer p = new Printer();
p.print("Hi! I am class STUDENT");
p.print();
PROOF=
ANSWER NO 3 =
// Define a method named 'studentMethod()' in class Question
// Call the method named 'print()' in class Question
// Define a method named 'studentMethod()' in class Question
void studentMethod(){
// Call the method named 'print()' in class Question
Question213 q = new Question213();
q.print(q);
}
PROOF =
QUESTION NO 4= TO call default constructor first and then any other constructor in the class Answer?
ANSWER NO 4 =
class Answer{
Answer(){
System.out.println("You got nothing.");
}
Answer(int marks, String type){
this();
System.out.println("You got "+marks+" for an "+ type);
}
}
PROOF =
Note: Output is Case Sensitive. ?
ANSWER NO 5 =
//Declare variable with name 'nptel', 'space' and 'java' and proper datatype.
//Initialize the variables with proper input
//Declare variable with name 'nptel', 'space' and 'java' and proper datatype.
String nptel,space,java;
//Initialize the variables with proper input
nptel="NPTEL";
space=" ";
java="JAVA";
PROOF =
THANKS FOR COMING U CAN COMMENT DOWN
Comments
Post a Comment