100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

Java: Classes and Objects UPDATED ACTUAL Exam Questions and CORRECT Answers

Rating
-
Sold
-
Pages
6
Grade
A+
Uploaded on
24-06-2025
Written in
2024/2025

Java: Classes and Objects UPDATED ACTUAL Exam Questions and CORRECT Answers

Institution
JAVA
Module
JAVA









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
JAVA
Module
JAVA

Document information

Uploaded on
June 24, 2025
Number of pages
6
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

Java: Classes and Objects UPDATED ACTUAL Exam Questions
and CORRECT Answers



Declaring a method - class Myclass{


static void sayHello(){

//sayHello is the method

System.out.println("Hello World!")

}



public static void main (String [ ] args) {
sayHello();

sayHello();

sayHello();

}

}

/* output:

Hello World!

Hello World!
Hello World!

*/



code reuse - You can write a method once, and use it multiple times, without having to rewrite
the code each time


Return value syntax - class MyClass {

, static int sum(int val1, int val2) {

return val1 + val2;

}


public static void main(String[ ] args) {

int x = sum(2, 5);

System.out.println(x);

}

}

//output 7


*Note: The return is saying to add val 1 and val 2 (parameters), as you can see in the next
function starting with public, there is a variable with x and the sum has (2,5) those two will be
added due to the method prior


Public - The class is accessible by any other class.



Package - A group of similar types of classes


Default - A variable or method declared with no access control modifier is available to any other
class in the same package.



Protected - Same as default, with the addition that subclasses can access protected methods and
variables of the superclass (learn more about subclasses and superclass later)



Private - Accessible only within the declared class itself
£10.01
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
GradeVaultAcademy

Also available in package deal

Get to know the seller

Seller avatar
GradeVaultAcademy Havard School
Follow You need to be logged in order to follow users or courses
Sold
2
Member since
6 months
Number of followers
0
Documents
841
Last sold
4 months ago
GradeVault Academy.

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions