Saturday, October 10, 2020

NPTEL PROGRAMMING IN JAVA WEEK 4 ANSWERS (JUL-DEC 2020)

 

QUESTION 1:


import java.io.*;
import java.util.*;
import static java.lang.System.*;

QUESTION 2:


// Create an object of Calendar class. 
java.util.Calendar current ;

// Use getInstance() method to initialize the Calendar object.
current = java.util.Calendar.getInstance();

// Initialize the int variable year with the current year
year = current.get(current.YEAR);

QUESTION 3:


interface ExtraLarge{
String extra = "This is extra-large";
void display();
}

class Large {
    public void Print() {
        System.out.println("This is large");
    }
}

class Medium extends Large {
    public void Print() {
       super.Print();  
        System.out.println("This is medium");
    }
}
class Small extends Medium {
    public void Print() {
        super.Print();  
        System.out.println("This is small");
    }
  }


class Question43 implements ExtraLarge{
    public static void main(String[] args) {
        Small s = new Small();
        s.Print();
  Question43 q = new Question43();
  q.display();
    }
  public void display(){
    System.out.println(extra);
  }
}


QUESTION 4:


// Call show() of First interface.
First.super.show();
// Call show() of Second interface.
Second.super.show();

QUESTION 5:


// Interface ShapeX is created
interface ShapeX {
 public String base = "This is Shape1";
 public void display1();
}

// Interface ShapeY is created which extends ShapeX
interface ShapeY extends ShapeX {
 public String base = "This is Shape2";
 public void display2();
}

// Class ShapeG is created which implements ShapeY
class ShapeG implements ShapeY {
 public String base = "This is Shape3";
 //Overriding method in ShapeX interface
 public void display1() {
  System.out.println("Circle: " + ShapeX.base);
 }
 // Override method in ShapeY interface
  public void display2(){
  System.out.println("Circle: " + ShapeY.base);}
}

0 Comments:

Post a Comment