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=

QUESTION NO 3= Complete the code segment to call print() method of class Question by creating a method named ‘studentMethod()’.?


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 =

QUESTION NO 5 = 
Complete the code segment to debug the program which is intended to print 'NPTEL JAVA'.

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 
 
                                         https://youtu.be/jCsoDl5HBiQ  

     

Comments

Popular posts from this blog

NPTEL JAVA WEEK 01 ASSIGNMENT SOLUTION