Programming in java Menu

Week 2: Programming Assignment 1

Complete the code segment to call the method  print() of class Student first and then call print() method of class School.

NOTE: Don't provide any INPUT in Sample Test Cases
 
// This is the class named School
class School { 
    // This is a method in class School
    public void print() { 
		System.out.println("Hi! I class SCHOOL."); 
    } 
} 
// This is the class named Student
class Student { 
	// This is a method in class Student
    public void print() { 
		System.out.println("Hi! I am class STUDENT"); 
    } 
}
public class Question21{ 
    public static void main(String args[]){
	// Create an object of class Student
	Student obj=new Student();
	// Call 'print()' method of class Student 
	obj.print();
	// Create an object of class School
	School obj1=new School();
	// Call 'print()' method of class School
	obj1.print();
	}
}	

Explanation Click here to wtach the video


Week 2: Programming Assignment 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.
--------------------------------

NOTE: Don't provide any INPUT in Sample Test Cases
 
// This is the class named Printer
class Printer { 
    // This are the methods in class Printer
    public void print() { 
		System.out.println("Hi! I class SCHOOL."); 
    } 
    public void print(String s) { 
		System.out.println(s); 
    } 
} 

public class Question22{ 
    public static void main(String[] args) {
		// Create an object of class Printer
Printer obj=new Printer();

// Call 'print()' methods for desired output
obj.print("Hi! I am class STUDENT");
obj.print();
	   
	   
	   

Explanation Click here to wtach the video


Week 2: Programming Assignment 3

Complete the code segment to call print() method of class Question by creating a method named ‘studentMethod()’.
 
// This is the main class Question
public class Question23{ 
    public static void main(String[] args) { 
		// Object of the main class is created
		Question23 q = new Question23();
		// Print method on object of Question class is called
		q.studentMethod();
    }
	
	// 'print()' method is defined in class Question
	void print(Question23 object){
		System.out.print("Well Done!");
	}
	// Define a method named 'studentMethod()' in class Question

// Call the method named 'print()' in class Question
  void studentMethod()
  {
    print(this);
  }
}
	   

Explanation Click here to wtach the video


Week 2: Programming Assignment 4

Complete the code segment to call default constructor first and then any other constructor in the class.
 
// This is the main class Question
public class Question214{
	public static void main(String[] args){
		Answer a = new Answer(10,"MCQ");
	}
}
class Answer{
	Answer(){
		System.out.println("You got nothing.");
	}
	Answer(int marks, String type){		
      this();
		System.out.print("You got "+marks+" for an "+ type);
	}
}

Explanation Click here to wtach the video


Week 2: Programming Assignment 5

Complete the code segment to debug / complete the program which is intended to print 'NPTEL JAVA'.
 
public class Question215{ 
    public static void main(String[] args) {
//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";		
	   
	   

Explanation Click here to wtach the video


Previous :Week 2 - Assignment Next :Week 3 - Assignment