Java Haezron (1)
Java Haezron (1)
[Type text]
Multiple Constructors
Source Code:
import java.io.*;
class Student
String name;
int regno;
int marks1,marks2,marks3;
Student()
name="raju";
regno=12345;
marks1=56;
marks2=47;
marks3=78;
name=n;
regno=r;
marks1=m1;
marks2=m2;
marks3=m3;
Student(Student s)
{
[Type text]
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
s1.display();
s2.display();
s3.display();
}
[Type text]
[Type text]
Inheritance:
Source Code:
import java.io.*;
class Name
String name="Swathi";
int age=20;
int m1=30,m2=30,m3=30;
int total;
void calc()
total=m1+m2+m3;
void show()
System.out.println("\nNAME:"+name+"\nAGE:"+age+"\nMARK1="+m1+"\nMARK2="+m
2+"\nMARK3="+m3+"\nTOTAL="+total);
class MultilevelInheritance
[Type text]
ob.calc();
ob.show();
}
[Type text]
[Type text]
Overriding Methods:
Source Code:
import java.io.*;
class Super
int x;
Super(int x)
this.x=x;
void display()
System.out.println("super x="+x);
int y;
Sub(int x,int y)
super(x);
this.y=y;
void display()
{
[Type text]
System.out.println("super x="+x);
System.out.println("sub y="+y);
class OverrideTest
s1.display();
}
[Type text]
[Type text]
Source Code:
import java.io.*;
class NumberSorting
int number[]={55,20,40,60,80,75,65,15,71,93};
int n = number.length;
System.out.println("Given list:");
for(int i=0;i<n;i++)
System.out.println(" "+number[i]);
System.out.println("/n");
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(number[i]<number[j])
int temp=number[i];
number[i]=number[j];
number[j]=temp;
[Type text]
System.out.println("Sorted List:");
for(int i=0;i<n;i++)
System.out.println(" "+number[i]);
System.out.println(" ");
}
[Type text]
[Type text]
Source Code:
import java.util.Scanner;
class AddMatrix
int row,col,i,j;
row = in.nextInt();
col=in.nextInt();
for(i=0;i<row;i++)
for(j=0;j<col;j++)
mat1[i][j]=in.nextInt();
System.out.println();
for(i=0;i<row;i++)
for(j=0;j<col;j++)
mat2[i][j]=in.nextInt();
System.out.println();
for(i=0;i<row;i++)
for(j=0;j<col;j++)
res[i][j]=mat1[i][j]+mat2[i][j];
System.out.println("Sum of matrics:-");
for(i=0;i<row;i++)
for(j=0;j<col;j++)
System.out.print(res[i][j]+"\t");
System.out.println();
}
[Type text]
[Type text]
Implementing Interface:
Source Code:
import java.lang.*;
import java.io.*;
interface Exam
void percent_cal();
class Student
String name;
int roll_no,mark1,mark2;
name=n;
roll_no=r;
mark1=m1;
mark2=m2;
void display()
System.out.println("RollNo of Student:"+roll_no);
System.out.println("Mark of Subject1:"+mark1);
[Type text]
System.out.println("Mmark of Subject2:"+mark2);
super(n,r,m1,m2);
int total=(mark1+mark2);
float percent=total*100/200;
System.out.println("Percentage:"+percent+"%");
void display()
super.display();
class MultipleinheritaneDemo
R.display();
[Type text]
R.percent_cal();
}
[Type text]
[Type text]
Source Code:
import java.io.*;
class MultiThread
System.out.print("Thread is started.....");
[Type text]
obj.start();
obj.start();
System.out.println("Thread is executed....");
}
[Type text]
[Type text]
package mypack;
int a = 100;
int b = 200;
Myclass.java
import mypack.Add;
a.addition();
}
[Type text]
[Type text]
Source Code:
import java.io.*;
class ExceptionDemo
int a=15;
for(int i=3;i>=0;i--)
try
System.out.println(a/i);
catch(ArithmeticException e)
System.out.println(e);
}
[Type text]
[Type text]
Source Code:
HelloworldApplet.java
import java.applet.*;
import java.awt.*;
g.drawString("Hellow World",25,50);
HelloworldApplet.html
<html>
</applet>
</hr>
</html>
[Type text]
[Type text]
Source Code:
import java.awt.*;
import java.awt.event.*;
MouseListenerExample2()
addMouseListener(this);
setSize(300,300);
setLayout(null);
setVisible(true);
Graphics g=getGraphics();
g.setColor(Color.BLUE);
g.fillOval(e.getX(),e.getY(),30,30);
new MouseListenerExample2();
Source Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
String msg;
int x=50;
int y=100;
{
[Type text]
addKeyListener(this);
requestFocus();
showStatus("Key Pressed");
repaint();
showStatus("Key Released");
repaint();
msg+=e.getKeyChar();
repaint();
g.drawString(msg,x,y);
}
[Type text]