16. Write a program in java to input roll no and marks of three subject of three students from keyboard. Calculate total marks using external class method print roll no and total marks of all student using main method class?

import java.io.DataInputStream; class Reading {                 int s1,s2,s3;                 void getData(int a,int b,int c)                 {                                 s1=a;                                 s2=b;                                 s3=c;                 }                 int total()                 {                                 return(s1+s2+s3);                 } } class Test {                 public static void main(String args[])                 {                                 DataInputStream in=new DataInputStream(System.in);                                 int rn=0,x,y,z,t=0,i;                                 Reading n=new... Continue Reading →

Advertisements

Methods overloading: –

Methods overloading: - Like other programming language, java also private facility for method overloading. It is possible to create methods that have the same name, but different parameter list and/or different definition. This is called method overloading. Method overloading is used when objects are required to perform different classes with different input parameters. When we... Continue Reading →

15. Write a program in java to input an integer number from keyboard. Calculate and print sum of input number from one to input number using external class?

import java.io.DataInputStream; class Calculate {                 int c=0,a;                 void getData(int x)                 {                                 a=x;                 }                 int outData()                 {                                 for(int j=1;j<=a;j++)                                                 c+=j;                                 return c;                 } } class Sum {                 public static void main(String args[])                 {                                 DataInputStream in=new DataInputStream(System.in);                                 int n,s=0;                                 try                                ... Continue Reading →

Constructor: –

Constructor: - We know that all objects that are created must be given initial value. It would be simpler and more concise to initialize an object when it is first created. Java supports a special type of method called constructor, that enables an object to initialize itself when it is created. Constructor have the same... Continue Reading →

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: