Java April 14th Batch Assignment

Java April 14th Batch Assignment

Postby h2kqa009491 » Mon Apr 28, 2014 11:55 pm

Assignment :1
Create a Super Class : Student.java having name,rollNumber
Create a Subclass JavaStudent.java extending Student.java. Add a constructor to intialize name and rollNumber.
Create a Client program . Create an instance of Student and access the name and rollNumber

Assignment :2
Given the below Code , What will be the result
Code: Select all
 public class TestDays {
   public enum Days {
      MON, TUE, WED
   };

   public static void main(String[] args) {
      for (Days d : Days.values());
      Days[] d2 = Days.values();
      System.out.println(d2[2]);
   }
    }


Assignment: 3
What is the output of the below Code
Code: Select all
public class Test extends Hobbit {
   public static void main(String[] args) {
      Short myGold = 7;
      System.out.println(countGold(myGold, 6));
   }
}

class Hobbit {
   int countGold(int x, int y) {
      return x + y;
   }
}


Assignment 4:
What is the output of the below Code

Code: Select all
enum Animals {
   DOG("woof"), CAT("meow"), FISH("burble");
   String sound;

   Animals(String s) {
      sound = s;
   }
}

class TestEnum {
   static Animals a;

   public static void main(String[] args) {
      System.out.println(a.DOG.sound + " " + a.FISH.sound);
   }
}
h2kqa009491
 
Posts: 1
Joined: Sun Apr 27, 2014 7:50 pm

Re: Java April 14th Batch Assignment

Postby h2k14jva000327 » Mon May 26, 2014 1:08 pm

Assignment 1
public class Student {
String name;
int rollNumber;

}
h2k14jva000327
 
Posts: 2
Joined: Mon May 19, 2014 10:05 am

Re: Java April 14th Batch Assignment

Postby h2k14jva000327 » Mon May 26, 2014 1:26 pm

by rashmi
Assignment 1:
public class Student {
String name;
int rollNumber;
}
public class JavaStudent extends Student {

JavaStudent(String r, int i){
this.rollNumber=i;
this.name= r;
}
}

public class ClientProgram {

public static void main(String[] args) {
Student s1= new Student();
JavaStudent j1= new JavaStudent("abc",11);

s1=j1;
System.out.println(s1.name);
System.out.println(s1.rollNumber);
}
}
Assignment 2:
output :-
WED
Assignment 3:
output: -
13
Assignment 4:
output:-
woof burble
h2k14jva000327
 
Posts: 2
Joined: Mon May 19, 2014 10:05 am


Return to Core Java

Who is online

Users browsing this forum: No registered users and 2 guests

cron