Skip to main content

12.SCOP rules and class specifiers

File: /home/saiesh/ADS/Assignment No 12/ads12_1.java
//Instance Variable
import java.io.*;
public class ads12_1
{
public String name;
private double salary;
public ads12_1 (String empName)
{
name=empName;
}
public void setSalary(double empSal)
{
salary=empSal;
}
public void printEmp()
{
System.out.println("Name\t: "+name);
System.out.println("Salary\t: "+salary);
}
public static void main(String[] args)
{
ads12_1 empOne=new ads12_1("Saiesh");
empOne.setSalary(10000);
empOne.printEmp();
}
}
/*
saiesh@saiesh :~$ javac ads12_1.java
saiesh@saiesh :~$ java ads12_1
Name
: Saiesh
Salary : 10000.0
saiesh@saiesh :~$ */
OUTPUT
Page 1 of 1

....................
File: /home/saiesh/ADS/Assignment No 12/ads12_2.java
Page 1 of 1
//Static Variable
import java.io.*;
public class ads12_2
{
private static double salary;
public static final String DEPARTMENT = "Development";
public static void main(String args[])
{
salary=1000;
System.out.println(DEPARTMENT+" average salary: "+salary);
}
}
/*
saiesh@saiesh :~$ javac ads12_2.java
saiesh@saiesh :~$ java ads12_2
Development average salary: 1000.0
saiesh@saiesh :~$ */
OUTPUT
.................
File: /home/saiesh/ADS/Assignment No 12/ads12_3.java
//Local Variable
public class ads12_3
{
public void pupAge()
{
int age=0;
age=age+7;
System.out.println("Puppy age is: "+age);
}
public static void main(String args[])
{
ads12_3 tes=new ads12_3();
tes.pupAge();
}
}
/*
saiesh@saiesh :~$ javac ads12_3.java
saiesh@saiesh :~$ java ads12_3
Puppy age is: 7
saiesh@saiesh :~$ */
OUTPUT
Page 1 of 1
...............
File: /home/saiesh/ADS/Assignment No 12/ads12_4.java
Page 1 of 1
//Global Variable
public class ads12_4
{
public ads12_4()
{
//auto generated constructor
}
public static void main(String[] args)
{
int n1;
n1=10;
if(n1==10)
{
int n2=20;
System.out.println("n1 and n2\t: "+n1+"
}
System.out.println("n1 is\t\t: "+n1);
}
}
/*
saiesh@saiesh :~$ javac ads12_4.java
saiesh@saiesh :~$ java ads12_4
n1 and n2
: 10 20
n1 is
: 10
saiesh@saiesh :~$ */
OUTPUT
"+n2);

Comments

Popular posts from this blog

PPL 1

NEW Unit III STRUCTURING OF PROGRAM MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of ‘Data Abstraction’? (a) Reduce Complexity (b) Binds together code and data (c) Parallelism (d) None of the mentioned Answer : a Explanation : An essential element of Object Oriented Programming is ‘Data Abstraction’ which means hiding things. Complexity is managed through abstraction. 2. Which of the following mechanisms is/are provided by Object Oriented Language to implement Object Oriented Model? (a) Encapsulation (b) Inheritance (c) Polymorphism (d) All of the mentioned Answer : d Explanation : None. 3. Which of these is the functionality of ‘Encapsulation’? (a) Binds together code and data (b) Using single interface for general class of actions. (c) Reduce Complexity (d) All of the mentioned Answer : a Explanation : ‘Encapsulation’ acts as protective wrapper that prevents code and data from being accessed by other code defined outside the...

EEE

EEE Unit-1 DC Machines MCQ's MULTIPLE CHOICE QUESTIONS ON UNIT 1: DC MACHINES Edit 1.The sole purpose of a Commutator in a dc generator is to------- ((A))increase output voltage ((B)) reduce sparking at brushes ((C)) provide smoother output ((D)) convert the induced ac into dc Hide ! Answer : D 2.In a dc generator, the generated emf is directly proportional to the------ ((A)) field current ((B)) pole flux ((C)) number of armature parallel paths ((D)) number of dummy coils Hide ! Answer:B 3.An ideal dc generator has .......... voltage regulation. ((A))low ((B))zero ((C))positive ((D))negative Hide ! Answer:B 4.Which generator may have poorest voltage regulation? ((A))series ((B))shunt((C))compound ((D))high Hide ! Answer:A 5.Voltage equation of a dc motor is----- ((A)) V = Eb + IaRa ((B)) Eb = V + IaRa ((C))V = Eb /IaRa ((D))V = Eb + Ia2Ra Hide ! Answer: A 6.Which of the following motor has the constant speed? ((A))Series motor ((B))Shunt motor ((C))Cumulatively compound motor ((D)...

replacing strings without using inbuild functions

 Q:replacing strings without using inbuild functions. We are using gcc compiler and terminal to compile the code and ubuntu OS. PROGRAM: #include<stdio.h> int strln1(char s1[]); int strln2(char s2[]); void strcpy1(char s1[],char s2[]); int main() {     char s1[30],s2[30];     int result1,result2;     printf("Enter the string s1");     scanf("%s",s1);     printf("Enter the string s2");     scanf("%s",s2);     printf("Your string s1 is %s",s1);     printf("\nYour string s2 is %s",s2);     result1=strln1(s1);     result2=strln2(s2);     printf("\nlength of string s1 is %d\n",result1);     printf("\nlength of string s2 is %d\n",result2);     strcpy1(s1,s2); } int strln1(char s1[]) {     int i,ln;   ...