×
DREAM IT. BELIEVE IT. ACHIEVE IT.
--Your friends at LectureNotes
Close

Java Programming

by Jntu Heroes
Type: PracticalInstitute: JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY Downloads: 36Views: 413Uploaded: 8 months agoAdd to Favourite

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

Jntu Heroes
Jntu Heroes
JAVA PROGRAMMING LAB 2011-2012 JAVA PROGRAMMING LABORATORY MANUAL 1
JAVA PROGRAMMING LAB 2011-2012 PROGRAM 1 /* Write a Java Program to define a class, describe its constructor, overload the Constructors and instantiate its object */ import java.lang.*; class student { String name; int regno; int marks1,marks2,marks3; // null constructor student() { name="raju"; regno=12345; marks1=56; marks2=47; marks3=78; } // parameterized constructor student(String n,int r,int m1,int m2,int m3) { name=n; regno=r; marks1=m1; marks2=m2; marks3=m3; } // copy constructor student(student s) { name=s.name; regno=s.regno; marks1=s.marks1; marks2=s.marks2; marks3=s.marks3; } void display() { System.out.println(name + "\t" +regno+ "\t" +marks1+ "\t" +marks2+ "\t" + marks3); } } class studentdemo { public static void main(String arg[]) { student s1=new student(); 2
JAVA PROGRAMMING LAB 2011-2012 student s2=new student("john",34266,58,96,84); student s3=new student(s1); s1.display(); s2.display(); s3.display(); } } ****************************OUTPUT************************************* c:\jdk1.6.0_26\bin>javac studentdemo.java c:\jdk1.6.0_26\bin>java studentdemo raju john raju 12345 56 34266 58 12345 56 47 96 47 78 84 78 3
JAVA PROGRAMMING LAB 2011-2012 PROGRAM 2 /* Write a Java Program to define a class, define instance methods for setting and Retrieving values of instance variables and instantiate its object.*/ import java.lang.*; class emp { String name; int id; String address; void getdata(String name,int id,String address) { this.name=name; this.id=id; this.address=address; } void putdata() { System.out.println("Employee details are :"); System.out.println("Name :" +name); System.out.println("ID :" +id); System.out.println("Address :" +address); } } class empdemo { public static void main(String arg[]) { emp e=new emp(); e.getdata("smith",76859,"gulbarga"); e.putdata(); } } **************************************OUTPUT***************************** c:\jdk1.6.0_26\bin>javac empdemo.java c:\jdk1.6.0_26\bin>java empdemo Employee details are : Name :smith ID :76859 Address :Gulbarga 4

Lecture Notes