Worksheet 1
1.
interface percentage
{
void percent();
}
class student
{
String name = "Rakesh";
int rollno = 87;
String dept = "BTech CSE";
int totalmarks = 90;
}
class result extends student implements percentage
{
void display()
{
System.out.println("Name of student is: "+name);
System.out.println("Roll no. of student is: "+rollno);
System.out.println("Department of student is: "+dept);
System.out.println("Total marks out of 100 of student is:
"+totalmarks);
}
public void percent()
{
float p = (totalmarks*100)/100;
System.out.println("The percentage is: "+p);
}
}
public class one
{
public static void main(String[] args)
{
result r = new result();
r.display();
r.percent();
}
}
1.Output
2.
interface playable
{
void play();
}
class football implements playable
{
public void play()
{
System.out.println("Playing Football");
}
}
class volleyball implements playable
{
public void play()
{
System.out.println("Playing Volleyball");
}
}
class basketball implements playable
{
public void play()
{
System.out.println("Playing Basketball");
}
}
public class two
{
public static void main(String[] args)
{
football f = new football();
volleyball v = new volleyball();
basketball b = new basketball();
f.play();
v.play();
b.play();
}
}
2.Output
3.
interface department
{
String dptName = "Civil Engineering";
String dptHead = "Mr. Jagadish";
void display();
}
class hostel
{
String hotelname = "Krishna";
String hostelLocation = "RV College of Engineering";
int nofrooms = 60;
void show()
{
System.out.println("The name of hostel is: "+hotelname);
System.out.println("The location of hostel is:
"+hostelLocation);
System.out.println("No. of rooms in hostel: "+nofrooms);
}
}
class student extends hostel implements department
{
String studentName = "Akshay", regdNo = "1RVU999",
electiveSubject = "Marketing";
float avgMarks = 50.67f;
public void display()
{
System.out.println("Name of student: "+studentName);
System.out.println("Register no. of student: "+regdNo);
System.out.println("Department name: "+dptName);
System.out.println("Department head: "+dptHead);
System.out.println("elective subject of student:
"+electiveSubject);
System.out.println("Average marks of student:
"+avgMarks);
}
}
public class three
{
public static void main(String[] args)
{
hostel h = new student();
department d = new student();
d.display();
h.show();
}
}
3.Output
4.
interface student
{
String name = "Akshay";
int rollno = 012;
}
interface internal extends student
{
int imarks1=20, imarks2=30;
void show();
}
interface external extends student
{
int emarks = 50;
void show();
}
class results implements internal, external
{
int total;
results()
{
total = imarks1+imarks2+emarks;
}
public void show()
{
System.out.println("The total marks is: "+this.total);
System.out.println("Result: PASS");
}
}
public class four
{
public static void main(String[] args)
{
results r = new results();
System.out.println("The name of student: "+r.name);
System.out.println("Roll no: "+r.rollno);
r.show();
}
}
4.Output