Professional Documents
Culture Documents
class length { public static void main(String args[]) { int arr[]={1,2,3,4,5,6,7,8,9}; int len=0,i; len=arr.length; System.out.println("The length of Array=" +len); } }
Output:-
Output:-
Output:-
superOb.j = 20; System.out.println("Contents of superOb: "); superOb.showij(); System.out.println(); /* The subclass has access to all public members of its superclass. */ subOb.i = 7; subOb.j = 8; subOb.k = 9; System.out.println("Contents of subOb: "); subOb.showij(); subOb.showk(); System.out.println(); System.out.println("Sum of i, j and k in subOb:"); subOb.sum(); } } /*The output from this program is shown here: Contents of superOb: i and j: 10 2 Contents of subOb: i and j: 7 8 k: 9 Sum of i, j and k in subOb: i+j+k: 24 As you can see, the subclass B includes all of the members of its superclass, A. This is why subOb can access i and j and call showij( ). Also, inside sum( ), i and j can be referred to directly, as if they were part of B.*/
Output:-
Output:-
class overload { public static void main(String args[]) { OverloadDemo ob = new OverloadDemo(); double result; // call all versions of test() ob.test(); ob.test(10); ob.test(10, 20); result = ob.test(123.25); System.out.println("Result of ob.test(123.25): " + result); } } /*This program generates the following output: No parameters a: 10 a and b: 10 20 double a: 123.25 Result of ob.test(123.25): 15190.5625*/
Output:-
void show() { System.out.println("k: " + k); } } class override { public static void main(String args[]) { B subOb = new B(1, 2, 3); subOb.show(); // this calls show() in B } }
Output:-
Output :-
Output:-
10. Write a program for print the length of string and reverse of that string.
class revstr { public static void main(String args[]) { StringBuffer arr=new StringBuffer("astbhuja pandey"); int len=0,i; len=arr.length(); System.out.println("the Length of string=" +len); arr.reverse(); System.out.println("reverse String =" +arr);
} }
Output:-
} catch(Exception e) { } } }
public class thread1 { public static void main(String args[]) { new mythread(); int x; x=0; try { while(x<15) { x++; System.out.println(x); Thread.sleep(1000); } } catch(Exception e) { System.out.println(e); } } }
Output:-
public class apple extends Applet { public void paint(Graphics g) { g.drawOval(40,40,140,140); g.drawLine(20,200,100,250); g.drawLine(10,10,10,80); g.drawLine(10,10,55,45); g.drawLine(10,80,55,45); } }
Output:-
13.
age=a; name=s; } } public class Info { public static void main(String[] as) { Constructor con=new Constructor(25,"Anand Mishra"); System.out.println("Name of Emp: "+con.name); System.out.println("Age of Emp: "+con.age); } }
class b implements a{ public void fun() { System.out.println("from class fun"); } public void sun() { System.out.println("from class sun"); }
} class Inter{ public static void main(String a[]) { b n=new b(); n.sun(); n.fun(); } } Output:-
c:\>javac Inter.java c:\>java Inter from class sun from class fun
} public abstract void sun(); } class b extends a{ public void sun() { System.out.println("from class b"); } } class Abs{ public static void main(String a[]) { b n=new b(); n.sun(); n.fun(); } } output:c:\>javac Abs.java c:\>java Abs from class b
from class a
{ public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException { String Name =req.getParameter("txtName"); res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("Welcome " + Name); out.close(); } } HTML CODE <html> <head> <title> First web application </title> </head> <body> <form method="get" action="welcomeservlet"> name <Input Type ="text" name ="txtName"> <br> <input type ="Submit" Value = "Submit">
</form> </body> </html> XML CODE <web-app> <servlet> <servlet-name>s1</servlet-name> <servlet-class>MyServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>s1</servlet-name> <url-pattern>welcomeservlet</url-pattern> </servlet-mapping> </web-app>
output:-
Nawframe(String f) { super(f); mb=new MenuBar(); mfile=new Menu("File"); medit=new Menu("Edit"); mnew=new MenuItem("New"); mexit=new MenuItem("Exit");
mnew.addActionListener(this); mexit.addActionListener(this);
mb.add(medit); setMenuBar(mb); } public void actionPerformed(ActionEvent w) { if(w.getSource()==mexit) { System.exit(0); } else if(w.getSource()==mnew) { Nawframe n=new Nawframe("New Frame"); n.setSize(100,100); n.setVisible(true); } } } public class Menitem { public static void main(String s[])
output:-