0% found this document useful (0 votes)
9 views2 pages

Java Questions Answers-1

The document provides a concise overview of basic Java programming concepts, including output, variables, conditional statements, loops, functions, arrays, string handling, classes, constructors, and inheritance. Each section contains code snippets illustrating the respective concepts. This serves as a foundational guide for beginners in Java programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Java Questions Answers-1

The document provides a concise overview of basic Java programming concepts, including output, variables, conditional statements, loops, functions, arrays, string handling, classes, constructors, and inheritance. Each section contains code snippets illustrating the respective concepts. This serves as a foundational guide for beginners in Java programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Basic Output
public class Main {
public static void main(String[] args) {
[Link]("Hello, Java World!");
}
}

2. Variables and Data Types


int number = 10;
double price = 99.99;
char grade = 'A';
boolean isJavaFun = true;

3. Conditional Statements
if (num > 0) {
[Link]("Positive");
} else if (num < 0) {
[Link]("Negative");
} else {
[Link]("Zero");
}

4. Loops (Multiplication Table)


for (int i = 1; i <= 10; i++) {
[Link](5 + " x " + i + " = " + (5 * i));
}

5. Functions (Methods)
public static int add(int a, int b) {
return a + b;
}

6. Arrays (Find Largest)


int largest = numbers[0];
for (int i = 1; i < [Link]; i++) {
if (numbers[i] > largest) {
largest = numbers[i];
}
}

7. String Handling (Count Vowels)


if (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'){
count++;
}

8. Class & Object


class Student {
String name;
int age;
void display(){
[Link](name + " " + age);
}
}

9. Constructor
Student(String n, int a){
name = n;
age = a;
}

10. Inheritance
class Dog extends Animal {
void sound(){
[Link]("Dog barks");
}
}

You might also like